Search in sources :

Example 1 with IAtomType

use of org.openscience.cdk.interfaces.IAtomType 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 IAtomType

use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.

the class AtomEnvironmentDescriptor method atomTypeToString.

public String atomTypeToString(int index) {
    IAtomType aType = getAtomType(index);
    String atomS = null;
    if (aType == null)
        atomS = "Misc";
    else
        atomS = aType.getAtomTypeName();
    return atomS;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType)

Example 3 with IAtomType

use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.

the class AtomEnvironmentDescriptorTest method testHybridizationStateATMatcher.

@Test
public void testHybridizationStateATMatcher() throws Exception {
    IAtomContainer mol = getMol();
    SybylAtomTypeMatcher h = SybylAtomTypeMatcher.getInstance(SilentChemObjectBuilder.getInstance());
    for (int i = 0; i < mol.getAtomCount(); i++) {
        IAtomType a = h.findMatchingAtomType(mol, mol.getAtom(i));
        Assert.assertTrue(a != null);
    }
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SybylAtomTypeMatcher(org.openscience.cdk.atomtype.SybylAtomTypeMatcher) Test(org.junit.Test)

Example 4 with IAtomType

use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.

the class AtomEnvironentMatrix method initAtomTypes.

protected String[] initAtomTypes(AtomTypeFactory factory, IAtomTypeMatcher atm) throws CDKException {
    // the idea is not to create objects if they already exist...
    if ((atm == null) || (factory == null)) {
        if (this.atm == null) {
            this.atm = SybylAtomTypeMatcher.getInstance(SilentChemObjectBuilder.getInstance());
            try {
                InputStream ins = getAtomTypeFactoryStream();
                this.factory = AtomTypeFactory.getInstance(ins, "owl", SilentChemObjectBuilder.getInstance());
            } catch (Exception x) {
                throw new CDKException(x.getMessage());
            }
            empty = true;
        } else
            empty = false;
    } else {
        this.atm = atm;
        this.factory = factory;
        empty = true;
    }
    if (empty) {
        atomTypes = this.factory.getAllAtomTypes();
        if (map == null)
            map = new TreeMap<String, Integer>();
        else
            map.clear();
        for (int i = 0; i < atomTypes.length; i++) {
            map.put(atomTypes[i].getAtomTypeName(), new Integer(i));
        }
    }
    // descriptorNames
    Set<String> dNames = new TreeSet<String>();
    String key = getKeyLevel0(null);
    if (!dNames.contains(key))
        dNames.add(key);
    for (int x1 = 0; x1 < atomTypes.length; x1++) {
        IAtomType key1 = atomTypes[x1];
        key = getKeyLevel0(key1);
        if (!dNames.contains(key))
            dNames.add(key);
        for (int x2 = x1; x2 < atomTypes.length; x2++) {
            IAtomType key2 = atomTypes[x2];
            for (int l = 1; l <= 8; l++) {
                key = getKeyLevel(key1, key2, l);
                if (!dNames.contains(key))
                    dNames.add(key);
            }
        }
        for (int l = 1; l <= 8; l++) {
            key = getKeyLevel(key1, null, l);
            if (!dNames.contains(key))
                dNames.add(key);
        }
    }
    // Collections.sort(dNames);
    return dNames.toArray(new String[dNames.size()]);
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) InputStream(java.io.InputStream) CDKException(org.openscience.cdk.exception.CDKException) TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap) CDKException(org.openscience.cdk.exception.CDKException) ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint)

Example 5 with IAtomType

use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.

the class AtomEnvironentMatrix method doCalculation.

/**
 * @param arg0
 * @param result
 *            result[i] contains the level at which ith atom is from the
 *            current atom (one set by setParameters)
 * @throws CDKException
 */
public HashIntDescriptorResult doCalculation(IAtomContainer atomContainer) throws CDKException {
    HashIntDescriptorResult sparseMatrix = null;
    try {
        sparseMatrix = new HashIntDescriptorResult(new TreeMap<String, Integer>());
        sparseMatrix.setMaxLevels(getMaxLevel());
        sparseMatrix.setFactory(factoryResource.substring(factoryResource.lastIndexOf("/") + 1));
    } catch (Exception x) {
        throw new CDKException(x.getMessage());
    }
    if ((atm == null) || (factory == null))
        descriptorNames = initAtomTypes(null, null);
    // maxLevel is how many bonds from the atom we will count atom types
    int natoms = atomContainer.getAtomCount();
    // do atom type matching
    atomTypes = factory.getAllAtomTypes();
    /*
		 * System.out.println("AtomTypes"); for (IAtomType at :atomTypes) {
		 * System.out.print(at.getAtomTypeName());System.out.print("\t");}
		 * System.out.println("End AtomTypes");
		 */
    // array of atom type integers
    int[] atomIndex = new int[natoms];
    for (int i = 0; i < natoms; i++) try {
        IAtomType a = atm.findMatchingAtomType(atomContainer, atomContainer.getAtom(i));
        if (a != null) {
            Object mappedType = map.get(a.getAtomTypeName());
            if (mappedType != null) {
                atomIndex[i] = ((Integer) mappedType).intValue();
            } else {
                atomIndex[i] = -1;
            }
        } else {
            // not found
            atomIndex[i] = -1;
        }
        String key = getKeyLevel0(atomIndex[i] >= 0 ? atomTypes[atomIndex[i]] : null);
        add(sparseMatrix.getResults(), key);
        if (addGenericTypes) {
            if ((atomIndex[i] > 0) && atomTypes[atomIndex[i]] != null) {
                if (isHal(atomTypes[atomIndex[i]]))
                    add(sparseMatrix.getResults(), "L0_Hal");
                if (isHet(atomTypes[atomIndex[i]]))
                    add(sparseMatrix.getResults(), "L0_Het");
                if (isHev(atomTypes[atomIndex[i]]))
                    add(sparseMatrix.getResults(), "L0_Hev");
            }
            add(sparseMatrix.getResults(), "L0_Any");
        }
    } catch (Exception x) {
        // x.printStackTrace();
        throw new CDKException(x.getMessage() + "\ninitConnectionMatrix");
    }
    // compute bond distances between all atoms
    int[][] aMatrix = PathTools.computeFloydAPSP(AdjacencyMatrix.getMatrix(atomContainer));
    for (int i = 0; i < natoms; i++) {
        IAtomType key1 = atomIndex[i] >= 0 ? atomTypes[atomIndex[i]] : null;
        for (int j = i; j < natoms; j++) {
            IAtomType key2 = atomIndex[j] >= 0 ? atomTypes[atomIndex[j]] : null;
            if (aMatrix[i][j] > 0 && (aMatrix[i][j] != 999999999) && (aMatrix[i][j] <= maxLevel)) {
                // j is not atom i and bonds less or
                // equal to maxlevel
                String key = getKeyLevel(key1, key2, aMatrix[i][j]);
                add(sparseMatrix.getResults(), key);
            }
        }
    }
    return sparseMatrix;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) CDKException(org.openscience.cdk.exception.CDKException) HashIntDescriptorResult(ambit2.core.data.HashIntDescriptorResult) TreeMap(java.util.TreeMap) CDKException(org.openscience.cdk.exception.CDKException) ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint)

Aggregations

IAtomType (org.openscience.cdk.interfaces.IAtomType)278 Test (org.junit.Test)171 IAtom (org.openscience.cdk.interfaces.IAtom)147 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)125 IBond (org.openscience.cdk.interfaces.IBond)59 CDKException (org.openscience.cdk.exception.CDKException)48 AbstractAtomTypeTest (org.openscience.cdk.test.atomtype.AbstractAtomTypeTest)34 CDKAtomTypeMatcher (org.openscience.cdk.atomtype.CDKAtomTypeMatcher)33 Atom (org.openscience.cdk.Atom)31 AtomContainer (org.openscience.cdk.silent.AtomContainer)24 PseudoAtom (org.openscience.cdk.PseudoAtom)23 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)22 AdductionSodiumLPReactionTest (org.openscience.cdk.reaction.type.AdductionSodiumLPReactionTest)21 HeterolyticCleavageSBReactionTest (org.openscience.cdk.reaction.type.HeterolyticCleavageSBReactionTest)21 HomolyticCleavageReactionTest (org.openscience.cdk.reaction.type.HomolyticCleavageReactionTest)21 RadicalSiteInitiationHReactionTest (org.openscience.cdk.reaction.type.RadicalSiteInitiationHReactionTest)21 SharingChargeDBReactionTest (org.openscience.cdk.reaction.type.SharingChargeDBReactionTest)21 IOException (java.io.IOException)16 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)15 ChemObject (org.openscience.cdk.ChemObject)12