Search in sources :

Example 16 with IReactionSet

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

the class HomolyticCleavageReactionTest method testNspChargeTripleB.

/**
 * A unit test suite for JUnit. Reaction:.
 * [N+]!#!C => [N*+]=[C*]
 */
@Test
public void testNspChargeTripleB() throws Exception {
    // Smiles("[N+]#C")
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "N"));
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.getAtom(0).setFormalCharge(+1);
    molecule.addBond(0, 1, IBond.Order.TRIPLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addBond(0, 2, IBond.Order.SINGLE);
    molecule.addBond(1, 3, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
    lpcheck.saturate(molecule);
    molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER, true);
    IAtomContainerSet setOfReactants = builder.newInstance(IAtomContainerSet.class);
    setOfReactants.addAtomContainer(molecule);
    IReactionProcess type = new HomolyticCleavageReaction();
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.TRUE);
    paramList.add(param);
    type.setParameterList(paramList);
    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    Assert.assertEquals(0, setOfReactions.getReactionCount());
}
Also used : IReactionProcess(org.openscience.cdk.reaction.IReactionProcess) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) ArrayList(java.util.ArrayList) SetReactionCenter(org.openscience.cdk.reaction.type.parameters.SetReactionCenter) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Example 17 with IReactionSet

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

the class HomolyticCleavageReactionTest method testMapping.

/**
 * A unit test suite for JUnit.
 */
@Test
public void testMapping() throws Exception {
    IReactionProcess type = new HomolyticCleavageReaction();
    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);
    /* automatic search of the center active */
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);
    /* initiate */
    makeSureAtomTypesAreRecognized(molecule);
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    Assert.assertEquals(4, setOfReactions.getReaction(0).getMappingCount());
    IAtom mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0));
    Assert.assertEquals(mappedProductA1, product.getAtom(0));
    IAtom mappedProductA2 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(1));
    Assert.assertEquals(mappedProductA2, product.getAtom(1));
}
Also used : IReactionProcess(org.openscience.cdk.reaction.IReactionProcess) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) ArrayList(java.util.ArrayList) SetReactionCenter(org.openscience.cdk.reaction.type.parameters.SetReactionCenter) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Example 18 with IReactionSet

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

the class HyperconjugationReactionTest method testMapping.

/**
 * A unit test suite for JUnit.
 */
@Test
public void testMapping() throws Exception {
    IReactionProcess type = new HyperconjugationReaction();
    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);
    /* automatic search of the center active */
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);
    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    IAtomContainer product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    IAtomContainer product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(1);
    Assert.assertEquals(3, setOfReactions.getReactionCount());
    Assert.assertEquals(2, setOfReactions.getReaction(0).getProductCount());
    // if these assertions fail the atom order may have changed
    IAtom mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(1));
    Assert.assertEquals(mappedProductA1, product1.getAtom(1));
    mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(2));
    Assert.assertEquals(mappedProductA1, product1.getAtom(2));
    mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(6));
    Assert.assertEquals(mappedProductA1, product2.getAtom(0));
}
Also used : IReactionProcess(org.openscience.cdk.reaction.IReactionProcess) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) ArrayList(java.util.ArrayList) SetReactionCenter(org.openscience.cdk.reaction.type.parameters.SetReactionCenter) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Example 19 with IReactionSet

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

the class HyperconjugationReactionTest method testInitiate_IAtomContainerSet_IAtomContainerSet.

/**
 * A unit test suite for JUnit. Reaction: [C+]-CC => C=CC + [H+]
 * Automatic search for the active center.
 */
@Test
@Override
public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception {
    IReactionProcess type = new HyperconjugationReaction();
    IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
    /* [C+]CC */
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.getAtom(0).setFormalCharge(1);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(0, 1, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(1, 2, IBond.Order.SINGLE);
    addExplicitHydrogens(molecule);
    setOfReactants.addAtomContainer(molecule);
    /* automatic search of the center active */
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);
    /* initiate */
    makeSureAtomTypesAreRecognized(molecule);
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    Assert.assertEquals(2, setOfReactions.getReactionCount());
    Assert.assertEquals(2, setOfReactions.getReaction(0).getProductCount());
    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    /* C=CC */
    IAtomContainer molecule2 = builder.newInstance(IAtomContainer.class);
    molecule2.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule2.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule2.addBond(0, 1, IBond.Order.DOUBLE);
    molecule2.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule2.addBond(1, 2, IBond.Order.SINGLE);
    addExplicitHydrogens(molecule2);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, product));
    product = setOfReactions.getReaction(0).getProducts().getAtomContainer(1);
    /* [H+] */
    molecule2 = builder.newInstance(IAtomContainer.class);
    molecule2.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule2.getAtom(0).setFormalCharge(1);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, product));
}
Also used : IReactionProcess(org.openscience.cdk.reaction.IReactionProcess) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) ArrayList(java.util.ArrayList) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) SetReactionCenter(org.openscience.cdk.reaction.type.parameters.SetReactionCenter) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Example 20 with IReactionSet

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

the class HyperconjugationReactionTest method testManuallyCentreActive.

/**
 * A unit test suite for JUnit. Reaction: [C-][C+]-C => [C-]C=C + [H+]
 * Manually put of the center active.
 */
@Test
public void testManuallyCentreActive() throws Exception {
    IReactionProcess type = new HyperconjugationReaction();
    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);
    /* manually put the center active */
    molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(6).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(5).setFlag(CDKConstants.REACTIVE_CENTER, true);
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.TRUE);
    paramList.add(param);
    type.setParameterList(paramList);
    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    Assert.assertEquals(1, setOfReactions.getReactionCount());
    Assert.assertEquals(2, setOfReactions.getReaction(0).getProductCount());
    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0);
    IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, queryAtom));
}
Also used : IReactionProcess(org.openscience.cdk.reaction.IReactionProcess) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) ArrayList(java.util.ArrayList) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) SetReactionCenter(org.openscience.cdk.reaction.type.parameters.SetReactionCenter) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Aggregations

IReactionSet (org.openscience.cdk.interfaces.IReactionSet)270 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)222 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)217 Test (org.junit.Test)208 ArrayList (java.util.ArrayList)195 IParameterReact (org.openscience.cdk.reaction.type.parameters.IParameterReact)192 IReactionProcess (org.openscience.cdk.reaction.IReactionProcess)162 ReactionProcessTest (org.openscience.cdk.reaction.ReactionProcessTest)159 SetReactionCenter (org.openscience.cdk.reaction.type.parameters.SetReactionCenter)159 IAtom (org.openscience.cdk.interfaces.IAtom)132 IReaction (org.openscience.cdk.interfaces.IReaction)84 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)45 CDKException (org.openscience.cdk.exception.CDKException)37 IBond (org.openscience.cdk.interfaces.IBond)37 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)29 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)28 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)17 IChemModel (org.openscience.cdk.interfaces.IChemModel)15 ICrystal (org.openscience.cdk.interfaces.ICrystal)11 IRingSet (org.openscience.cdk.interfaces.IRingSet)10