Search in sources :

Example 11 with IReactionSet

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

the class SharingChargeDBReactionTest method testInitiate_IAtomContainerSet_IAtomContainerSet.

/**
 * A unit test suite for JUnit. Reaction: C-C=[O+] => C-[C+]O|
 * Automatic search of the center active.
 */
@Test
@Override
public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception {
    IReactionProcess type = new SharingChargeDBReaction();
    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);
    /* initiate */
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    Assert.assertEquals(1, setOfReactions.getReactionCount());
    Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount());
    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    Assert.assertEquals(1, product.getAtom(1).getFormalCharge().intValue());
    Assert.assertEquals(0, product.getConnectedLonePairsCount(product.getAtom(1)));
    /* C[C+]O| */
    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)

Example 12 with IReactionSet

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

the class SharingChargeSBReactionTest method testNsp3ChargeSingleB.

/**
 * A unit test suite for JUnit. Reaction:.
 * C[N+]!-!C => CN + [C+]
 */
@Test
public void testNsp3ChargeSingleB() throws Exception {
    // Smiles("C[N+]C")
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addAtom(builder.newInstance(IAtom.class, "N"));
    molecule.getAtom(1).setFormalCharge(+1);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(0, 1, IBond.Order.SINGLE);
    molecule.addBond(1, 2, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addBond(0, 3, IBond.Order.SINGLE);
    molecule.addBond(0, 4, IBond.Order.SINGLE);
    molecule.addBond(0, 5, IBond.Order.SINGLE);
    molecule.addBond(1, 6, IBond.Order.SINGLE);
    molecule.addBond(1, 7, IBond.Order.SINGLE);
    molecule.addBond(2, 8, IBond.Order.SINGLE);
    molecule.addBond(2, 9, IBond.Order.SINGLE);
    molecule.addBond(2, 10, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
    lpcheck.saturate(molecule);
    molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
    setOfReactants.addAtomContainer(molecule);
    IReactionProcess type = new SharingChargeSBReaction();
    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());
    // expected products
    // Smiles("CN")
    IAtomContainer expected1 = builder.newInstance(IAtomContainer.class);
    expected1.addAtom(builder.newInstance(IAtom.class, "C"));
    expected1.addAtom(builder.newInstance(IAtom.class, "N"));
    expected1.addBond(0, 1, IBond.Order.SINGLE);
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addBond(0, 2, IBond.Order.SINGLE);
    expected1.addBond(0, 3, IBond.Order.SINGLE);
    expected1.addBond(0, 4, IBond.Order.SINGLE);
    expected1.addBond(1, 5, IBond.Order.SINGLE);
    expected1.addBond(1, 6, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected1);
    lpcheck.saturate(expected1);
    IAtomContainer product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    QueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected1);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product1, queryAtom));
    // Smiles("[C+]")
    IAtomContainer expected2 = builder.newInstance(IAtomContainer.class);
    expected2.addAtom(builder.newInstance(IAtom.class, "C"));
    expected2.getAtom(0).setFormalCharge(+1);
    expected2.addAtom(builder.newInstance(IAtom.class, "H"));
    expected2.addAtom(builder.newInstance(IAtom.class, "H"));
    expected2.addAtom(builder.newInstance(IAtom.class, "H"));
    expected2.addBond(0, 1, IBond.Order.SINGLE);
    expected2.addBond(0, 2, IBond.Order.SINGLE);
    expected2.addBond(0, 3, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected2);
    IAtomContainer product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(1);
    queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected2);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product2, 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) IAtom(org.openscience.cdk.interfaces.IAtom) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Example 13 with IReactionSet

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

the class SharingChargeSBReactionTest method testInitiate_IAtomContainerSet_IAtomContainerSet.

/**
 * A unit test suite for JUnit. Reaction:  methoxymethane.
 * C[O+]!-!C =>  CO + [C+]
 */
@Test
@Override
public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception {
    IReactionProcess type = new SharingChargeSBReaction();
    IAtomContainerSet setOfReactants = getExampleReactants();
    /* initiate */
    List<IParameterReact> paramList = new ArrayList<>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);
    Assert.assertEquals(3, setOfReactions.getReactionCount());
    Assert.assertEquals(2, setOfReactions.getReaction(0).getProductCount());
    IAtomContainer product1 = setOfReactions.getReaction(1).getProducts().getAtomContainer(0);
    IAtomContainer molecule1 = getExpectedProducts().getAtomContainer(0);
    IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product1);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule1, queryAtom));
    IAtomContainer product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(1);
    IAtomContainer expected2 = getExpectedProducts().getAtomContainer(0);
    queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected2);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product2, 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)

Example 14 with IReactionSet

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

the class SharingChargeSBReactionTest method testCDKConstants_REACTIVE_CENTER.

/**
 * A unit test suite for JUnit.
 */
@Test
public void testCDKConstants_REACTIVE_CENTER() throws Exception {
    IReactionProcess type = new SharingChargeSBReaction();
    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);
    /* manually put the reactive center */
    molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(1).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);
    IAtomContainer reactant = setOfReactions.getReaction(0).getReactants().getAtomContainer(0);
    Assert.assertTrue(molecule.getAtom(1).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(1).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(2).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(2).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getBond(1).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getBond(1).getFlag(CDKConstants.REACTIVE_CENTER));
}
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) Test(org.junit.Test) ReactionProcessTest(org.openscience.cdk.reaction.ReactionProcessTest)

Example 15 with IReactionSet

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

the class SharingChargeSBReactionTest method testNsp2ChargeSingleB.

/**
 * A unit test suite for JUnit. Reaction:.
 * C=[N+]!-!C => C=N + [C+]
 */
@Test
public void testNsp2ChargeSingleB() throws Exception {
    // Smiles("C=[N+]C")
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addAtom(builder.newInstance(IAtom.class, "N"));
    molecule.getAtom(1).setFormalCharge(1);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(0, 1, IBond.Order.DOUBLE);
    molecule.addBond(1, 2, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addAtom(builder.newInstance(IAtom.class, "H"));
    molecule.addBond(0, 3, IBond.Order.SINGLE);
    molecule.addBond(0, 4, IBond.Order.SINGLE);
    molecule.addBond(1, 5, IBond.Order.SINGLE);
    molecule.addBond(2, 6, IBond.Order.SINGLE);
    molecule.addBond(2, 7, IBond.Order.SINGLE);
    molecule.addBond(2, 8, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
    lpcheck.saturate(molecule);
    molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
    setOfReactants.addAtomContainer(molecule);
    IReactionProcess type = new SharingChargeSBReaction();
    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());
    // expected products
    // Smiles("C=N")
    IAtomContainer expected1 = builder.newInstance(IAtomContainer.class);
    expected1.addAtom(builder.newInstance(IAtom.class, "C"));
    expected1.addAtom(builder.newInstance(IAtom.class, "N"));
    expected1.addBond(0, 1, IBond.Order.DOUBLE);
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addAtom(builder.newInstance(IAtom.class, "H"));
    expected1.addBond(0, 2, IBond.Order.SINGLE);
    expected1.addBond(0, 3, IBond.Order.SINGLE);
    expected1.addBond(1, 4, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected1);
    lpcheck.saturate(expected1);
    IAtomContainer product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);
    QueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected1);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product1, queryAtom));
    // Smiles("[C+]")
    IAtomContainer expected2 = builder.newInstance(IAtomContainer.class);
    expected2.addAtom(builder.newInstance(IAtom.class, "C"));
    expected2.getAtom(0).setFormalCharge(+1);
    expected2.addAtom(builder.newInstance(IAtom.class, "H"));
    expected2.addAtom(builder.newInstance(IAtom.class, "H"));
    expected2.addAtom(builder.newInstance(IAtom.class, "H"));
    expected2.addBond(0, 1, IBond.Order.SINGLE);
    expected2.addBond(0, 2, IBond.Order.SINGLE);
    expected2.addBond(0, 3, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected2);
    IAtomContainer product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(1);
    queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected2);
    Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product2, 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) IAtom(org.openscience.cdk.interfaces.IAtom) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) 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