use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.
the class FingerprintGenerator method process.
public BitSet process(IAtomContainer object) throws AmbitException {
try {
if ((object == null) || (object.getAtomCount() == 0))
throw new EmptyMoleculeException();
long fp_time = System.currentTimeMillis();
IAtomContainer c = object;
if (hydrogens) {
if (hAdder == null)
hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
c = object.clone();
hAdder.addImplicitHydrogens(c);
MoleculeTools.convertImplicitToExplicitHydrogens(c);
} else {
if (object.getBondCount() > 1) {
for (IAtom atom : object.atoms()) if (atom.getImplicitHydrogenCount() == null) {
if ("H".equals(atom.getSymbol()))
atom.setImplicitHydrogenCount(0);
}
c = AtomContainerManipulator.copyAndSuppressedHydrogens(object);
} else
c = object;
}
fp_time = System.currentTimeMillis() - fp_time;
object.setProperty(AmbitCONSTANTS.FingerprintTIME, new Long(fp_time));
return fingerprinter.getBitFingerprint(c).asBitSet();
} catch (AmbitException x) {
throw x;
} catch (Exception x) {
throw new AmbitException("Error generating fingerprint\t" + x.getMessage(), x);
}
}
use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.
the class HNMRShifts method findAllHAtomEnvironmentInstances.
void findAllHAtomEnvironmentInstances() throws EmptyMoleculeException {
for (int i = 0; i < knowledgeBase.hAtomEnvironments.size(); i++) {
HAtomEnvironment hae = knowledgeBase.hAtomEnvironments.get(i);
if (!hae.flagUse)
continue;
List<List<IAtom>> atMaps = hae.groupMatch.getMappings(molecule);
if (atMaps.isEmpty())
continue;
for (int k = 0; k < atMaps.size(); k++) {
HAtomEnvironmentInstance haeInst = new HAtomEnvironmentInstance();
haeInst.hEnvironment = hae;
int n = atMaps.get(k).size();
haeInst.atoms = new IAtom[n];
for (int r = 0; r < n; r++) haeInst.atoms[r] = atMaps.get(k).get(r);
hAtEnvInstances.add(haeInst);
registerHAtomEnvironmentInstance(haeInst);
}
}
}
use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.
the class RetroSynthesis method findRuleInstances.
ArrayList<IRetroSynthRuleInstance> findRuleInstances(IAtomContainer str, RetroSynthRule rule) throws EmptyMoleculeException {
ArrayList<IRetroSynthRuleInstance> instances = new ArrayList<IRetroSynthRuleInstance>();
smrkMan.getIsomorphismTester().setQuery(rule.reaction.reactant);
SmartsParser.prepareTargetForSMARTSSearch(rule.reaction.reactantFlags, str);
List<List<IAtom>> rMaps = smrkMan.getNonOverlappingMappings(str);
for (int i = 0; i < rMaps.size(); i++) {
RetroSynthRuleInstance rInstance = new RetroSynthRuleInstance();
rInstance.setAtoms(rMaps.get(i));
rInstance.setRule(rule);
instances.add(rInstance);
System.out.print("rule: " + rule.smirks + " ");
smrkMan.printSSMap(str, rInstance.getAtoms());
}
return instances;
}
use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.
the class AutomaticTestUtilities method calcBitVectorStrings.
public int calcBitVectorStrings() throws EmptyMoleculeException {
// Input file is interpreted as str. keys set
// for each DB structure BitVector is calculated and saved to the output
// file
// Loading the structure keys
Vector<String> externKeySet = new Vector<String>();
try {
File file = new File(inFileName);
RandomAccessFile f = new RandomAccessFile(file, "r");
String line;
long length = f.length();
while (f.getFilePointer() < length) {
line = f.readLine();
String smiles = line.trim();
if (!smiles.equals(""))
externKeySet.add(smiles);
}
f.close();
} catch (Exception e) {
System.out.println("Probleb with the input file:");
e.printStackTrace();
return (-1);
}
Screening screen = new Screening(externKeySet);
if (dbFileName.endsWith(".txt") || dbFileName.endsWith(".smi")) {
try {
File file = new File(dbFileName);
RandomAccessFile f = new RandomAccessFile(file, "r");
String line;
long length = f.length();
int record = 0;
while (f.getFilePointer() < length) {
line = f.readLine();
String smiles = line.trim();
IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smiles);
BitSet bs = screen.getStructureKeyBits(mol);
String s = screen.getBitSetString(bs);
output(s + endLine);
record++;
if (record % 100 == 0)
System.out.println("rec " + record);
}
f.close();
} catch (Exception e) {
System.out.println("Probleb with the SMILES DB file :");
e.printStackTrace();
return (-1);
}
return (0);
}
try {
IChemObjectBuilder b = SilentChemObjectBuilder.getInstance();
IteratingSDFReader reader = new IteratingSDFReader(new FileReader(dbFileName), b);
int record = 0;
int readComp = 0;
while (reader.hasNext()) {
record++;
if (record > this.nDBStr)
break;
if ((record % 100) == 0)
System.out.println("rec " + record + " (" + readComp + ")");
Object o = reader.next();
if (o instanceof IAtomContainer) {
readComp++;
IAtomContainer mol = (IAtomContainer) o;
if (mol.getAtomCount() == 0)
continue;
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
CDKHueckelAromaticityDetector.detectAromaticity(mol);
BitSet bs = screen.getStructureKeyBits(mol);
String s = screen.getBitSetString(bs);
output(s + endLine);
// Test
// BitSet bs2 = screen.stringToBitSet(s);
// String s2 = screen.getBitSetString(bs2);
// System.out.println(s + " " + s2);
}
}
} catch (Exception e) {
System.out.println("Problem with the DB file:");
e.printStackTrace();
return (-1);
}
return (0);
}
use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.
the class StructureKeysBitSetGenerator method prepareKeySequences.
protected synchronized void prepareKeySequences(List<String> keys, int nKeys) throws EmptyMoleculeException {
smartsKeys = keys;
IQueryAtomContainer query;
sequences.clear();
smartsQueries.clear();
SmartsParser parser = new SmartsParser();
for (int i = 0; i < nKeys; i++) {
query = parser.parse(smartsKeys.get(i));
// parser.setNeededDataFlags(); --> This should not be needed for the key smarts queries
isoTester.setQuery(query);
List<QuerySequenceElement> sequence = isoTester.transferSequenceToOwner();
sequences.add(sequence);
smartsQueries.add(query);
}
}
Aggregations