Search in sources :

Example 1 with IAtomTypeMatcher

use of org.openscience.cdk.atomtype.IAtomTypeMatcher in project ambit-mirror by ideaconsult.

the class AtomEnvironmentMatrixDescriptor method setParameters.

/**
 * Sets the parameters attribute of the AtomEnvironmentDescriptor object
 *
 * @param params
 *            - parameters, as below params[0] MaxLevel, optional , default
 *            3 params[1] perceiveCyclicAtoms, optional , default false
 *            params[2] AtomTypeFactory factory, optional, default
 *            AtomTypeFactory.getInstance(
 *            "org/openscience/cdk/dict/data/sybyl-atom-types.owl")
 *            params[3] AtomTypeMatcher atm, optional , default
 *            HybridizationStateATMatcher
 */
public void setParameters(Object[] allParams) throws CDKException {
    AtomTypeFactory afactory = null;
    IAtomTypeMatcher amatcher = null;
    for (int i = 0; i < allParams.length; i++) {
        switch(i) {
            case 0:
                {
                    if (!(allParams[i] instanceof Integer))
                        throw new CDKException(String.format("The %d parameter must be of type Integer", i + 1));
                    setMaxLevel(((Integer) allParams[i]).intValue());
                    break;
                }
            case 1:
                {
                    if (!(allParams[i] instanceof Boolean))
                        throw new CDKException(String.format("The %d parameter must be of type AtomTypeFactory", i + 1));
                    afactory = (AtomTypeFactory) allParams[i];
                    break;
                }
            case 2:
                {
                    if (!(allParams[i] instanceof Boolean))
                        throw new CDKException(String.format("The %d parameter must be of type IAtomTypeMatcher", i + 1));
                    amatcher = (IAtomTypeMatcher) allParams[i];
                    break;
                }
            default:
                {
                    throw new CDKException(String.format("%s only expects %d parameters", getClass().getName(), allParams.length));
                }
        }
    }
    ;
    try {
        descriptorNames = initAtomTypes(afactory, amatcher);
    } catch (Exception x) {
        throw new CDKException(x.getMessage());
    }
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) IAtomTypeMatcher(org.openscience.cdk.atomtype.IAtomTypeMatcher) CDKException(org.openscience.cdk.exception.CDKException)

Example 2 with IAtomTypeMatcher

use of org.openscience.cdk.atomtype.IAtomTypeMatcher in project cdk by cdk.

the class AbstractAtomTypeTest method assertAtomTypes.

/**
 * Helper method to test if atom types are correctly perceived. Meanwhile, it maintains a list
 * of atom types that have been tested so far, which allows testing afterwards that all atom
 * types are at least tested once.
 *
 * @param testedAtomTypes   List of atom types tested so far.
 * @param expectedTypes     Expected atom types for the atoms given in <code>mol</code>.
 * @param mol               The <code>IAtomContainer</code> with <code>IAtom</code>s for which atom types should be perceived.
 * @throws Exception     Thrown if something went wrong during the atom type perception.
 */
public void assertAtomTypes(Map<String, Integer> testedAtomTypes, String[] expectedTypes, IAtomContainer mol) throws Exception {
    Assert.assertEquals("The number of expected atom types is unequal to the number of atoms", expectedTypes.length, mol.getAtomCount());
    IAtomTypeMatcher atm = getAtomTypeMatcher(mol.getBuilder());
    for (int i = 0; i < expectedTypes.length; i++) {
        IAtom testedAtom = mol.getAtom(i);
        IAtomType foundType = atm.findMatchingAtomType(mol, testedAtom);
        assertAtomType(testedAtomTypes, "Incorrect perception for atom " + i, expectedTypes[i], foundType);
        assertConsistentProperties(mol, testedAtom, foundType);
        // test for bug #1890702: configure, and then make sure the same atom type is perceived
        AtomTypeManipulator.configure(testedAtom, foundType);
        IAtomType secondType = atm.findMatchingAtomType(mol, testedAtom);
        assertAtomType(testedAtomTypes, "Incorrect perception *after* assigning atom type properties for atom " + i, expectedTypes[i], secondType);
    }
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomTypeMatcher(org.openscience.cdk.atomtype.IAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with IAtomTypeMatcher

use of org.openscience.cdk.atomtype.IAtomTypeMatcher in project ambit-mirror by ideaconsult.

the class AtomEnvironmentDescriptor method setParameters.

/**
 * Sets the parameters attribute of the AtomEnvironmentDescriptor object
 *
 * @param params
 *            - parameters, as below params[0] MaxLevel, optional , default
 *            3 params[1] perceiveCyclicAtoms, optional , default false
 *            params[2] AtomTypeFactory factory, optional, default
 *            AtomTypeFactory.getInstance(
 *            "org/openscience/cdk/dict/data/sybyl-atom-types.owl")
 *            params[3] AtomTypeMatcher atm, optional , default
 *            HybridizationStateATMatcher
 */
public void setParameters(Object[] allParams) throws CDKException {
    AtomTypeFactory afactory = null;
    IAtomTypeMatcher amatcher = null;
    for (int i = 0; i < allParams.length; i++) {
        switch(i) {
            case 0:
                {
                    if (!(allParams[i] instanceof Integer))
                        throw new CDKException(String.format("The %d parameter must be of type Integer", i + 1));
                    maxLevel = ((Integer) allParams[i]).intValue();
                    break;
                }
            case 1:
                {
                    if (!(allParams[i] instanceof Boolean))
                        throw new CDKException(String.format("The %d parameter must be of type AtomTypeFactory", i + 1));
                    afactory = (AtomTypeFactory) allParams[i];
                    break;
                }
            case 2:
                {
                    if (!(allParams[i] instanceof Boolean))
                        throw new CDKException(String.format("The %d parameter must be of type IAtomTypeMatcher", i + 1));
                    amatcher = (IAtomTypeMatcher) allParams[i];
                    break;
                }
            default:
                {
                    throw new CDKException(String.format("%s only expects %d parameters", getClass().getName(), allParams.length));
                }
        }
    }
    ;
    try {
        initAtomTypes(afactory, amatcher);
    } catch (Exception x) {
        throw new CDKException(x.getMessage());
    }
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) IAtomTypeMatcher(org.openscience.cdk.atomtype.IAtomTypeMatcher) CDKException(org.openscience.cdk.exception.CDKException)

Example 4 with IAtomTypeMatcher

use of org.openscience.cdk.atomtype.IAtomTypeMatcher in project cdk by cdk.

the class AbstractAtomTypeTest method assertAtomTypeNames.

public void assertAtomTypeNames(Map<String, Integer> testedAtomTypes, String[] expectedTypes, IAtomContainer mol) throws Exception {
    Assert.assertEquals("The number of expected atom types is unequal to the number of atoms", expectedTypes.length, mol.getAtomCount());
    IAtomTypeMatcher atm = getAtomTypeMatcher(mol.getBuilder());
    for (int i = 0; i < expectedTypes.length; i++) {
        IAtom testedAtom = mol.getAtom(i);
        IAtomType foundType = atm.findMatchingAtomType(mol, testedAtom);
        assertAtomType(testedAtomTypes, "Incorrect perception for atom " + i, expectedTypes[i], foundType);
    }
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomTypeMatcher(org.openscience.cdk.atomtype.IAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

IAtomTypeMatcher (org.openscience.cdk.atomtype.IAtomTypeMatcher)4 AtomTypeFactory (org.openscience.cdk.config.AtomTypeFactory)2 CDKException (org.openscience.cdk.exception.CDKException)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 IAtomType (org.openscience.cdk.interfaces.IAtomType)2