use of org.openscience.cdk.Reaction in project cdk by cdk.
the class AbstractReactionLabeller method labelReaction.
public IReaction labelReaction(IReaction reaction, ICanonicalMoleculeLabeller labeller) {
System.out.println("labelling");
IReaction canonReaction = new Reaction();
Map<IAtomContainer, int[]> permutationMap = new HashMap<>();
IAtomContainerSet canonicalProducts = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
for (IAtomContainer product : reaction.getProducts().atomContainers()) {
IAtomContainer canonicalForm = labeller.getCanonicalMolecule(product);
if (fixAtomMappingCastType) {
fixAtomMapping(canonicalForm);
}
IAtomContainer canonicalMolecule = canonicalForm.getBuilder().newInstance(IAtomContainer.class, canonicalForm);
permutationMap.put(canonicalMolecule, labeller.getCanonicalPermutation(product));
canonicalProducts.addAtomContainer(canonicalMolecule);
}
IAtomContainerSet canonicalReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
for (IAtomContainer reactant : reaction.getReactants().atomContainers()) {
IAtomContainer canonicalForm = labeller.getCanonicalMolecule(reactant);
if (fixAtomMappingCastType) {
fixAtomMapping(canonicalForm);
}
IAtomContainer canonicalMolecule = canonicalForm.getBuilder().newInstance(IAtomContainer.class, canonicalForm);
permutationMap.put(canonicalMolecule, labeller.getCanonicalPermutation(reactant));
canonicalReactants.addAtomContainer(canonicalMolecule);
}
canonReaction.setProducts(canonicalProducts);
canonReaction.setReactants(canonicalReactants);
cloneAndSortMappings(reaction, canonReaction, permutationMap);
return canonReaction;
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class GeometryToolsTest method testShiftReactionVertical_IAtomContainer_Rectangle2D_Rectangle2D_double.
@Test
public void testShiftReactionVertical_IAtomContainer_Rectangle2D_Rectangle2D_double() throws Exception {
IAtom atom1 = new Atom("C");
atom1.setPoint2d(new Point2d(0, 1));
IAtom atom2 = new Atom("C");
atom2.setPoint2d(new Point2d(1, 0));
IAtomContainer react1 = new AtomContainer();
IReaction reaction = new Reaction();
reaction.addReactant(react1);
react1.addAtom(atom1);
react1.addAtom(atom2);
react1.addBond(0, 1, IBond.Order.SINGLE);
IReaction reaction2 = (IReaction) reaction.clone();
IAtomContainer react2 = reaction2.getReactants().getAtomContainer(0);
// shift the second reaction up
GeometryTools.shiftReactionVertical(reaction2, GeometryTools.getRectangle2D(react2), GeometryTools.getRectangle2D(react1), 1.0);
// assert all coordinates of the second reaction moved up
AtomContainerDiff.diff(react1, react2);
LoggingToolFactory.createLoggingTool(getClass()).info("R1: " + GeometryTools.getRectangle2D(react1));
LoggingToolFactory.createLoggingTool(getClass()).info("R2: " + GeometryTools.getRectangle2D(react2));
for (int i = 0; i < 2; i++) {
atom1 = react1.getAtom(0);
atom2 = react2.getAtom(0);
// so, x coordinates should be the same
Assert.assertEquals(atom1.getPoint2d().x, atom2.getPoint2d().x, 0.0);
// but, y coordinates should not
Assert.assertTrue(atom1.getPoint2d().y < atom2.getPoint2d().y);
}
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class GeometryToolsTest method testGetBondLengthAverage_MultiReaction.
/**
* Tests if the bond length average is calculated based on all
* {@link IAtomContainer}s in the IReaction.
*/
@Test
public void testGetBondLengthAverage_MultiReaction() {
IReaction reaction = new Reaction();
// mol 1
IAtom atom1 = new Atom("C");
atom1.setPoint2d(new Point2d(0, 0));
IAtom atom2 = new Atom("C");
atom2.setPoint2d(new Point2d(1, 0));
IAtomContainer acont = new AtomContainer();
reaction.addReactant(acont);
acont.addAtom(atom1);
acont.addAtom(atom2);
acont.addBond(0, 1, IBond.Order.SINGLE);
// mol 2
atom1 = new Atom("C");
atom1.setPoint2d(new Point2d(0, 0));
atom2 = new Atom("C");
atom2.setPoint2d(new Point2d(3, 0));
acont = new AtomContainer();
reaction.addProduct(acont);
acont.addAtom(atom1);
acont.addAtom(atom2);
acont.addBond(0, 1, IBond.Order.SINGLE);
Assert.assertEquals(2.0, GeometryTools.getBondLengthAverage(reaction), 0.0);
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class ChemFileManipulatorTest method setUp.
@Before
public void setUp() {
molecule1 = new AtomContainer();
atomInMol1 = new Atom("Cl");
molecule1.addAtom(atomInMol1);
molecule1.addAtom(new Atom("Cl"));
bondInMol1 = new Bond(atomInMol1, molecule1.getAtom(1));
molecule1.addBond(bondInMol1);
molecule2 = new AtomContainer();
atomInMol2 = new Atom("O");
atomInMol2.setImplicitHydrogenCount(2);
molecule2.addAtom(atomInMol2);
moleculeSet = new AtomContainerSet();
moleculeSet.addAtomContainer(molecule1);
moleculeSet.addAtomContainer(molecule2);
reaction = new Reaction();
reaction.addReactant(molecule1);
reaction.addProduct(molecule2);
reactionSet = new ReactionSet();
reactionSet.addReaction(reaction);
chemModel = new ChemModel();
chemModel.setMoleculeSet(moleculeSet);
chemModel.setReactionSet(reactionSet);
chemSequence1 = new ChemSequence();
chemSequence1.addChemModel(chemModel);
chemSequence2 = new ChemSequence();
chemFile = new ChemFile();
chemFile.addChemSequence(chemSequence1);
chemFile.addChemSequence(chemSequence2);
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class ChemModelManipulatorTest method testRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom.
@Test
public void testRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom() {
IAtomContainer mol1 = new AtomContainer();
IAtom atom1 = new Atom("Cl");
mol1.addAtom(atom1);
mol1.addAtom(new Atom("Cl"));
IBond bond1 = new Bond(mol1.getAtom(0), mol1.getAtom(1));
mol1.addBond(bond1);
IAtomContainer mol2 = new AtomContainer();
IAtom atom2 = new Atom("I");
mol2.addAtom(atom2);
mol2.addAtom(new Atom("I"));
IBond bond2 = new Bond(mol2.getAtom(0), mol2.getAtom(1));
mol2.addBond(bond2);
IAtomContainerSet molSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
molSet.addAtomContainer(mol1);
IReaction r = new Reaction();
r.addProduct(mol2);
IReactionSet rSet = new ReactionSet();
rSet.addReaction(r);
IChemModel model = new ChemModel();
model.setMoleculeSet(molSet);
model.setReactionSet(rSet);
IAtom otherAtom = new Atom("Cl");
Assert.assertEquals(2, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(4, ChemModelManipulator.getAtomCount(model));
ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, otherAtom);
Assert.assertEquals(2, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(4, ChemModelManipulator.getAtomCount(model));
ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, atom1);
Assert.assertEquals(1, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(3, ChemModelManipulator.getAtomCount(model));
ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, atom2);
Assert.assertEquals(0, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(2, ChemModelManipulator.getAtomCount(model));
}
Aggregations