Search in sources :

Example 1 with IMapping

use of org.openscience.cdk.interfaces.IMapping in project cdk by cdk.

the class MappingTest method testMapping_IChemObject_IChemObject.

@Test
public void testMapping_IChemObject_IChemObject() {
    IMapping mapping = new Mapping(newChemObject().getBuilder().newInstance(IAtom.class), newChemObject().getBuilder().newInstance(IAtom.class));
    Assert.assertNotNull(mapping);
}
Also used : IMapping(org.openscience.cdk.interfaces.IMapping) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping) Test(org.junit.Test) AbstractMappingTest(org.openscience.cdk.test.interfaces.AbstractMappingTest)

Example 2 with IMapping

use of org.openscience.cdk.interfaces.IMapping in project cdk by cdk.

the class MappingTest method testMapping_IChemObject_IChemObject.

@Test
public void testMapping_IChemObject_IChemObject() {
    IChemObject object = newChemObject();
    IMapping mapping = new Mapping(object.getBuilder().newInstance(IAtom.class), object.getBuilder().newInstance(IAtom.class));
    Assert.assertNotNull(mapping);
}
Also used : IChemObject(org.openscience.cdk.interfaces.IChemObject) IMapping(org.openscience.cdk.interfaces.IMapping) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping) Test(org.junit.Test) AbstractMappingTest(org.openscience.cdk.test.interfaces.AbstractMappingTest)

Example 3 with IMapping

use of org.openscience.cdk.interfaces.IMapping in project cdk by cdk.

the class AdductionLPMechanism method initiate.

/**
 * Initiates the process for the given mechanism. The atoms and bonds to apply are mapped between
 * reactants and products.
 *
 * @param atomContainerSet
 * @param atomList    The list of atoms taking part in the mechanism. Only allowed two atoms.
 * @param bondList    The list of bonds taking part in the mechanism. not allowed bonds.
 *
 * @return            The Reaction mechanism
 */
@Override
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
    if (atomContainerSet.getAtomContainerCount() != 2) {
        throw new CDKException("AdductionLPMechanism expects two IAtomContainer's");
    }
    if (atomList.size() != 2) {
        throw new CDKException("AdductionLPMechanism expects two atoms in the ArrayList");
    }
    if (bondList != null) {
        throw new CDKException("AdductionLPMechanism don't expect bonds in the ArrayList");
    }
    IAtomContainer molecule1 = atomContainerSet.getAtomContainer(0);
    IAtomContainer molecule2 = atomContainerSet.getAtomContainer(1);
    IAtomContainer reactantCloned;
    try {
        reactantCloned = atomContainerSet.getAtomContainer(0).clone();
        reactantCloned.add(atomContainerSet.getAtomContainer(1).clone());
    } catch (CloneNotSupportedException e) {
        throw new CDKException("Could not clone IAtomContainer!", e);
    }
    // Atom 1: excess in charge
    IAtom atom1 = atomList.get(0);
    IAtom atom1C = reactantCloned.getAtom(molecule1.indexOf(atom1));
    // Atom 2: deficient in charge
    IAtom atom2 = atomList.get(1);
    IAtom atom2C = reactantCloned.getAtom(molecule1.getAtomCount() + molecule2.indexOf(atom2));
    IBond newBond = molecule1.getBuilder().newInstance(IBond.class, atom1C, atom2C, IBond.Order.SINGLE);
    reactantCloned.addBond(newBond);
    int charge = atom1C.getFormalCharge();
    atom1C.setFormalCharge(charge + 1);
    List<ILonePair> lps = reactantCloned.getConnectedLonePairsList(atom1C);
    reactantCloned.removeLonePair(lps.get(lps.size() - 1));
    atom1C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom1C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    charge = atom2C.getFormalCharge();
    atom2C.setFormalCharge(charge - 1);
    atom2C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom2C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    IReaction reaction = atom1C.getBuilder().newInstance(IReaction.class);
    reaction.addReactant(molecule1);
    /* mapping */
    for (IAtom atom : molecule1.atoms()) {
        IMapping mapping = atom1C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule1.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    for (IAtom atom : molecule2.atoms()) {
        IMapping mapping = atom1C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule2.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    reaction.addProduct(reactantCloned);
    return reaction;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) ILonePair(org.openscience.cdk.interfaces.ILonePair) IBond(org.openscience.cdk.interfaces.IBond) IReaction(org.openscience.cdk.interfaces.IReaction) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping)

Example 4 with IMapping

use of org.openscience.cdk.interfaces.IMapping in project cdk by cdk.

the class HomolyticCleavageMechanism method initiate.

/**
 * Initiates the process for the given mechanism. The atoms to apply are mapped between
 * reactants and products.
 *
 * @param atomContainerSet
 * @param atomList    The list of atoms taking part in the mechanism. Only allowed two atoms.
 *                    Both atoms acquire a ISingleElectron
 * @param bondList    The list of bonds taking part in the mechanism. Only allowed one bond
 * @return            The Reaction mechanism
 */
@Override
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
    if (atomContainerSet.getAtomContainerCount() != 1) {
        throw new CDKException("TautomerizationMechanism only expects one IAtomContainer");
    }
    if (atomList.size() != 2) {
        throw new CDKException("HomolyticCleavageMechanism expects two atoms in the ArrayList");
    }
    if (bondList.size() != 1) {
        throw new CDKException("HomolyticCleavageMechanism only expect one bond in the ArrayList");
    }
    IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
    IAtomContainer reactantCloned;
    try {
        reactantCloned = molecule.clone();
    } catch (CloneNotSupportedException e) {
        throw new CDKException("Could not clone IAtomContainer!", e);
    }
    IAtom atom1 = atomList.get(0);
    IAtom atom1C = reactantCloned.getAtom(molecule.indexOf(atom1));
    IAtom atom2 = atomList.get(1);
    IAtom atom2C = reactantCloned.getAtom(molecule.indexOf(atom2));
    IBond bond1 = bondList.get(0);
    int posBond1 = molecule.indexOf(bond1);
    if (bond1.getOrder() == IBond.Order.SINGLE)
        reactantCloned.removeBond(reactantCloned.getBond(posBond1));
    else
        BondManipulator.decreaseBondOrder(reactantCloned.getBond(posBond1));
    reactantCloned.addSingleElectron(bond1.getBuilder().newInstance(ISingleElectron.class, atom1C));
    reactantCloned.addSingleElectron(bond1.getBuilder().newInstance(ISingleElectron.class, atom2C));
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    // check if resulting atom type is reasonable
    atom1C.setHybridization(null);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom1C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    // check if resulting atom type is reasonable: an acceptor atom cannot be charged positive*/
    atom2C.setHybridization(null);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom2C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    IReaction reaction = atom2C.getBuilder().newInstance(IReaction.class);
    reaction.addReactant(molecule);
    /* mapping */
    for (IAtom atom : molecule.atoms()) {
        IMapping mapping = atom2C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    if (bond1.getOrder() != IBond.Order.SINGLE) {
        reaction.addProduct(reactantCloned);
    } else {
        IAtomContainerSet moleculeSetP = ConnectivityChecker.partitionIntoMolecules(reactantCloned);
        for (int z = 0; z < moleculeSetP.getAtomContainerCount(); z++) {
            reaction.addProduct(moleculeSetP.getAtomContainer(z));
        }
    }
    return reaction;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ISingleElectron(org.openscience.cdk.interfaces.ISingleElectron) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IBond(org.openscience.cdk.interfaces.IBond) IReaction(org.openscience.cdk.interfaces.IReaction) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping)

Example 5 with IMapping

use of org.openscience.cdk.interfaces.IMapping in project cdk by cdk.

the class RadicalSiteRearrangementMechanism method initiate.

/**
 * Initiates the process for the given mechanism. The atoms to apply are mapped between
 * reactants and products.
 *
 * @param atomContainerSet
 * @param atomList    The list of atoms taking part in the mechanism. Only allowed two atoms.
 *                    The first atom is the atom which must be moved and the second
 *                    is the atom which receives the atom1 and the third is the atom which loss
 *                    the first atom
 * @param bondList    The list of bonds taking part in the mechanism. Only allowed one bond.
 * 					  It is the bond which is moved
 * @return            The Reaction mechanism
 */
@Override
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
    if (atomContainerSet.getAtomContainerCount() != 1) {
        throw new CDKException("RadicalSiteRearrangementMechanism only expects one IAtomContainer");
    }
    if (atomList.size() != 3) {
        throw new CDKException("RadicalSiteRearrangementMechanism expects three atoms in the ArrayList");
    }
    if (bondList.size() != 1) {
        throw new CDKException("RadicalSiteRearrangementMechanism only expect one bond in the ArrayList");
    }
    IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
    IAtomContainer reactantCloned;
    try {
        reactantCloned = molecule.clone();
    } catch (CloneNotSupportedException e) {
        throw new CDKException("Could not clone IAtomContainer!", e);
    }
    // Atom to be moved
    IAtom atom1 = atomList.get(0);
    IAtom atom1C = reactantCloned.getAtom(molecule.indexOf(atom1));
    // Atom to receive the new bonding with a ISingleElectron
    IAtom atom2 = atomList.get(1);
    IAtom atom2C = reactantCloned.getAtom(molecule.indexOf(atom2));
    // Atom which loss the atom
    IAtom atom3 = atomList.get(2);
    IAtom atom3C = reactantCloned.getAtom(molecule.indexOf(atom3));
    // Bond to move
    IBond bond1 = bondList.get(0);
    int posBond1 = molecule.indexOf(bond1);
    reactantCloned.removeBond(reactantCloned.getBond(posBond1));
    IBond newBond = atom1.getBuilder().newInstance(IBond.class, atom1C, atom2C, IBond.Order.SINGLE);
    reactantCloned.addBond(newBond);
    List<ISingleElectron> selectron = reactantCloned.getConnectedSingleElectronsList(atom2C);
    reactantCloned.removeSingleElectron(selectron.get(selectron.size() - 1));
    atom2C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom2C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    reactantCloned.addSingleElectron(atom2C.getBuilder().newInstance(ISingleElectron.class, atom3C));
    atom3C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom3C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    IReaction reaction = atom2C.getBuilder().newInstance(IReaction.class);
    reaction.addReactant(molecule);
    /* mapping */
    for (IAtom atom : molecule.atoms()) {
        IMapping mapping = atom2C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    reaction.addProduct(reactantCloned);
    return reaction;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ISingleElectron(org.openscience.cdk.interfaces.ISingleElectron) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) IReaction(org.openscience.cdk.interfaces.IReaction) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping)

Aggregations

IMapping (org.openscience.cdk.interfaces.IMapping)34 IAtom (org.openscience.cdk.interfaces.IAtom)24 IReaction (org.openscience.cdk.interfaces.IReaction)21 Test (org.junit.Test)14 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)14 CDKException (org.openscience.cdk.exception.CDKException)12 CDKAtomTypeMatcher (org.openscience.cdk.atomtype.CDKAtomTypeMatcher)11 IAtomType (org.openscience.cdk.interfaces.IAtomType)11 IBond (org.openscience.cdk.interfaces.IBond)11 IChemObject (org.openscience.cdk.interfaces.IChemObject)8 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)6 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)5 ILonePair (org.openscience.cdk.interfaces.ILonePair)5 AbstractMappingTest (org.openscience.cdk.test.interfaces.AbstractMappingTest)3 InputStream (java.io.InputStream)2 Reaction (org.openscience.cdk.Reaction)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)2 Color (java.awt.Color)1 IOException (java.io.IOException)1