Search in sources :

Example 1 with CDKAtomTypeMatcher

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;
}
Also used : IPseudoAtom(org.openscience.cdk.interfaces.IPseudoAtom) IAtomType(org.openscience.cdk.interfaces.IAtomType) ArrayList(java.util.ArrayList) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with CDKAtomTypeMatcher

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));
    }
}
Also used : CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with CDKAtomTypeMatcher

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));
    }
}
Also used : CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with CDKAtomTypeMatcher

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));
    }
}
Also used : CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with CDKAtomTypeMatcher

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));
    }
}
Also used : CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

CDKAtomTypeMatcher (org.openscience.cdk.atomtype.CDKAtomTypeMatcher)61 IAtom (org.openscience.cdk.interfaces.IAtom)58 IAtomType (org.openscience.cdk.interfaces.IAtomType)33 CDKException (org.openscience.cdk.exception.CDKException)23 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)20 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)14 IMapping (org.openscience.cdk.interfaces.IMapping)11 IReaction (org.openscience.cdk.interfaces.IReaction)11 IBond (org.openscience.cdk.interfaces.IBond)10 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)7 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)6 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)6 ILonePair (org.openscience.cdk.interfaces.ILonePair)5 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)5 List (java.util.List)4 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)4 SmilesParser (org.openscience.cdk.smiles.SmilesParser)4 ArrayList (java.util.ArrayList)3 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)3 Test (org.junit.Test)2