use of org.openscience.cdk.atomtype.CDKAtomTypeMatcher in project ambit-mirror by ideaconsult.
the class AtomConfigurator method process.
public IAtomContainer process(IAtomContainer mol) throws AmbitException {
if (mol == null)
throw new AmbitException("Null molecule!");
if (mol.getAtomCount() == 0)
throw new AmbitException("No atoms!");
logger.fine("Configuring atom types ...");
// AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(mol.getBuilder());
Iterator<IAtom> atoms = mol.atoms().iterator();
List<String> errors = null;
while (atoms.hasNext()) {
IAtom atom = atoms.next();
if (!(atom instanceof IPseudoAtom))
try {
IAtomType matched = matcher.findMatchingAtomType(mol, atom);
if (matched != null) {
AtomTypeManipulator.configure(atom, matched);
atom.setValency(matched.getValency());
atom.setAtomicNumber(matched.getAtomicNumber());
atom.setExactMass(matched.getExactMass());
} else {
if (errors == null)
errors = new ArrayList<String>();
if (errors.indexOf(atom.getSymbol()) < 0)
errors.add(String.format("%s", atom.getSymbol()));
}
} catch (Exception x) {
if (errors == null)
errors = new ArrayList<String>();
if (errors.indexOf(atom.getSymbol()) < 0) {
errors.add(String.format("%s", atom.getSymbol()));
}
}
}
if ((errors != null) && "true".equals(Preferences.getProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES))) {
Collections.sort(errors);
throw new AmbitException(errors.toString());
}
/*
CDKHueckelAromaticityDetector.detectAromaticity(molecule);
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(mol.getBuilder());
Iterator<IAtom> atoms = mol.atoms();
while (atoms.hasNext()) {
IAtom atom = atoms.next();
IAtomType type = matcher.findMatchingAtomType(mol, atom);
try {
AtomTypeManipulator.configure(atom, type);
logger.debug("Found " + atom.getSymbol() + " of type " + type.getAtomTypeName());
} catch (Exception x) {
logger.error(x.getMessage() + " " + atom.getSymbol(),x);
if ("true".equals(Preferences.getProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES))) {
throw new AmbitException(atom.getSymbol(),x);
}
}
}
*/
atoms = mol.atoms().iterator();
while (atoms.hasNext()) {
IAtom atom = atoms.next();
if ((atom.getAtomicNumber() == null) || (atom.getAtomicNumber() == 0)) {
Integer no = PeriodicTable.getAtomicNumber(atom.getSymbol());
if (no != null)
atom.setAtomicNumber(no.intValue());
}
}
return mol;
}
use of org.openscience.cdk.atomtype.CDKAtomTypeMatcher in project cdk by cdk.
the class RadicalSiteRrGammaReactionTest method makeSureAtomTypesAreRecognized.
/**
* Test to recognize if a IAtomContainer matcher correctly identifies the CDKAtomTypes.
*
* @param molecule The IAtomContainer to analyze
* @throws CDKException
*/
private void makeSureAtomTypesAreRecognized(IAtomContainer molecule) throws CDKException {
Iterator<IAtom> atoms = molecule.atoms().iterator();
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
while (atoms.hasNext()) {
IAtom nextAtom = atoms.next();
Assert.assertNotNull("Missing atom type for: " + nextAtom, matcher.findMatchingAtomType(molecule, nextAtom));
}
}
use of org.openscience.cdk.atomtype.CDKAtomTypeMatcher in project cdk by cdk.
the class SharingChargeSBReactionTest method makeSureAtomTypesAreRecognized.
/**
* Test to recognize if a IAtomContainer matcher correctly identifies the CDKAtomTypes.
*
* @param molecule The IAtomContainer to analyze
* @throws CDKException
*/
private void makeSureAtomTypesAreRecognized(IAtomContainer molecule) throws Exception {
Iterator<IAtom> atoms = molecule.atoms().iterator();
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
while (atoms.hasNext()) {
IAtom nextAtom = atoms.next();
Assert.assertNotNull("Missing atom type for: " + nextAtom, matcher.findMatchingAtomType(molecule, nextAtom));
}
}
use of org.openscience.cdk.atomtype.CDKAtomTypeMatcher in project cdk by cdk.
the class HyperconjugationReactionTest method makeSureAtomTypesAreRecognized.
/**
* Test to recognize if a IAtomContainer matcher correctly identifies the CDKAtomTypes.
*
* @param molecule The IAtomContainer to analyze
* @throws CDKException
*/
private void makeSureAtomTypesAreRecognized(IAtomContainer molecule) throws Exception {
Iterator<IAtom> atoms = molecule.atoms().iterator();
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
while (atoms.hasNext()) {
IAtom nextAtom = atoms.next();
Assert.assertNotNull("Missing atom type for: " + nextAtom, matcher.findMatchingAtomType(molecule, nextAtom));
}
}
use of org.openscience.cdk.atomtype.CDKAtomTypeMatcher in project cdk by cdk.
the class PiBondingMovementReactionTest method makeSureAtomTypesAreRecognized.
/**
* Test to recognize if a IAtomContainer matcher correctly identifies the CDKAtomTypes.
*
* @param molecule The IAtomContainer to analyze
*/
private void makeSureAtomTypesAreRecognized(IAtomContainer molecule) throws Exception {
Iterator<IAtom> atoms = molecule.atoms().iterator();
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
while (atoms.hasNext()) {
IAtom nextAtom = atoms.next();
Assert.assertNotNull("Missing atom type for: " + nextAtom, matcher.findMatchingAtomType(molecule, nextAtom));
}
}
Aggregations