Exemplo n.º 1
0
  @Test
  public void testMakeAtomContainer() {

    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();

    IAtom atom = builder.newInstance(IAtom.class, "C");
    IAtom exclude = builder.newInstance(IAtom.class, "C");

    IAtom a1 = builder.newInstance(IAtom.class, "C");
    IAtom a2 = builder.newInstance(IAtom.class, "C");

    IBond[] bonds =
        new IBond[] {
          builder.newInstance(IBond.class, atom, exclude),
          builder.newInstance(IBond.class, a1, a2),
          builder.newInstance(IBond.class, a1, atom),
          builder.newInstance(IBond.class, a2, exclude)
        };

    IAtomContainer part = FragmentUtils.makeAtomContainer(atom, Arrays.asList(bonds), exclude);

    assertThat(part.getAtomCount(), is(3));
    assertThat(part.getBondCount(), is(2));

    Assert.assertTrue(part.contains(atom));
    Assert.assertTrue(part.contains(a1));
    Assert.assertTrue(part.contains(a2));
    Assert.assertFalse(part.contains(exclude));

    Assert.assertTrue(part.contains(bonds[1]));
    Assert.assertTrue(part.contains(bonds[2]));
  }
Exemplo n.º 2
0
  public ChemWizard() {
    smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
    smrkMan.setFlagProcessResultStructures(true);
    smrkMan.setFlagAddImplicitHAtomsOnResultProcess(true);

    LOGGER.setLevel(Level.FINEST);
  }
Exemplo n.º 3
0
/** @author John May */
public class ChemSpiderAdapter extends AbstractSoapService<ChemSpiderIdentifier>
    implements StructureService<ChemSpiderIdentifier> {

  private static final Logger LOGGER = Logger.getLogger(ChemSpiderAdapter.class);

  private static final IChemObjectBuilder BUILDER = SilentChemObjectBuilder.getInstance();

  private SearchSoap service;
  private SearchLocator locator = new SearchLocator();

  @Override
  public ChemSpiderIdentifier getIdentifier() {
    return new ChemSpiderIdentifier();
  }

  @Override
  public IAtomContainer getStructure(ChemSpiderIdentifier identifier) {

    try {

      StringPreference key = ServicePreferences.getInstance().getPreference("CHEM_SPIDER_KEY");

      if (key.get().isEmpty()) {
        System.err.println("No ChemSpider key available: please input the key via preferences!");
        return BUILDER.newInstance(IAtomContainer.class);
      }

      CompoundInfo info =
          service.getCompoundInfo(Integer.parseInt(identifier.getAccession()), key.get());

      InChIGeneratorFactory inchiFactory = InChIGeneratorFactory.getInstance();
      InChIToStructure inchi2structure = inchiFactory.getInChIToStructure(info.getInChI(), BUILDER);

      return inchi2structure.getAtomContainer();

    } catch (CDKException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (RemoteException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    return BUILDER.newInstance(IAtomContainer.class);
  }

  @Override
  public boolean startup() {
    if (service != null) return true;
    try {
      service = locator.getSearchSoap();
    } catch (ServiceException ex) {
      LOGGER.error("Startup failed on SOAP Web Service: " + ex.getMessage());
    }
    return service != null;
  }
}
Exemplo n.º 4
0
  /**
   * Just to ensure it doesn't throw exceptions
   *
   * @throws Exception
   */
  @Test(timeout = 1000)
  public void testAcyclic() throws Exception {
    String smiles = "CCCCCCC";
    SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);
  }
Exemplo n.º 5
0
 static Graph convert(
     IAtomContainer ac,
     boolean perceiveAromaticity,
     boolean isomeric,
     boolean aromatic,
     boolean atomClasses)
     throws Exception {
   AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac);
   CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance()).addImplicitHydrogens(ac);
   if (perceiveAromaticity) Aromaticity.cdkLegacy().apply(ac);
   return new CDKToBeam(isomeric, aromatic, atomClasses).toBeamGraph(ac);
 }
Exemplo n.º 6
0
  private IAtomContainer parseSMILES() {
    if (SMILES_PARSER == null) {
      SMILES_PARSER = new SmilesParser(SilentChemObjectBuilder.getInstance());
    }
    try {
      atomContainer = new AtomContainer(SMILES_PARSER.parseSmiles(getValue()));
    } catch (CDKException ex) {
      LOGGER.error("Could not parse SMILES ", ex);
      atomContainer = new AtomContainer();
    }

    return atomContainer;
  }
Exemplo n.º 7
0
  @Test
  public void testTraversal_Chain() {

    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();

    IAtom[] atoms =
        new IAtom[] {
          builder.newInstance(IAtom.class, "C"),
          builder.newInstance(IAtom.class, "C"),
          builder.newInstance(IAtom.class, "C"),
          builder.newInstance(IAtom.class, "C"),
          builder.newInstance(IAtom.class, "C"),
          builder.newInstance(IAtom.class, "C")
        };
    IBond[] bonds =
        new IBond[] {
          builder.newInstance(IBond.class, atoms[0], atoms[1]),
          builder.newInstance(IBond.class, atoms[1], atoms[2]),
          builder.newInstance(IBond.class, atoms[2], atoms[3]),
          builder.newInstance(IBond.class, atoms[3], atoms[4]),
          builder.newInstance(IBond.class, atoms[4], atoms[5])
        };

    IAtomContainer m = builder.newInstance(IAtomContainer.class, 0, 0, 0, 0);
    m.setAtoms(atoms);
    m.setBonds(bonds);

    List<IBond> accumulator = new ArrayList<IBond>();

    // traverse from one end
    FragmentUtils.traverse(m, atoms[0], accumulator);

    assertThat(accumulator.size(), is(5));
    assertThat(accumulator.get(0), is(bonds[0]));
    assertThat(accumulator.get(1), is(bonds[1]));
    assertThat(accumulator.get(2), is(bonds[2]));
    assertThat(accumulator.get(3), is(bonds[3]));
    assertThat(accumulator.get(4), is(bonds[4]));

    // traverse from the middle
    accumulator.clear();
    FragmentUtils.traverse(m, atoms[3], accumulator);

    assertThat(accumulator.size(), is(5));

    assertThat(accumulator.get(0), is(bonds[2]));
    assertThat(accumulator.get(1), is(bonds[1]));
    assertThat(accumulator.get(2), is(bonds[0]));
    assertThat(accumulator.get(3), is(bonds[3]));
    assertThat(accumulator.get(4), is(bonds[4]));
  }
 private void updatePageComplete(Text field) {
   setPageComplete(false);
   String smiles = field.getText();
   if (smiles.length() != 0) {
     SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
     try {
       parser.parseSmiles(smiles);
       wizard.setSMILES(smiles);
     } catch (InvalidSmilesException exception) {
       setMessage(exception.getMessage());
       setErrorMessage("The given SMILES is invalid.");
       return;
     }
   }
   setPageComplete(true);
   setMessage(null);
   setErrorMessage(null);
 }
Exemplo n.º 9
0
  @Test(timeout = 1000)
  public void testPyrrole_Silent() throws Exception {
    String smiles = "c2ccc3n([H])c1ccccc1c3(c2)";
    SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC));
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(6, doubleBondCount);
  }
/**
 * TestSuite that runs all QSAR tests.
 *
 * @cdk.module test-qsaratomic
 */
public class StabilizationPlusChargeDescriptorTest extends AtomicDescriptorTest {

  private static final IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
  LonePairElectronChecker lpcheck = new LonePairElectronChecker();

  public StabilizationPlusChargeDescriptorTest() {
    descriptor = new StabilizationPlusChargeDescriptor();
  }

  @Before
  public void setUp() throws Exception {
    setDescriptor(StabilizationPlusChargeDescriptor.class);
  }

  /**
   * A unit test for JUnit
   *
   * @throws Exception
   */
  @Test
  public void testStabilizationPlusChargeDescriptor() throws Exception {

    IAtomContainer mol = builder.newInstance(IAtomContainer.class);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.getAtom(0).setFormalCharge(-1);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.getAtom(1).setFormalCharge(1);
    mol.addBond(0, 1, Order.SINGLE);
    mol.addAtom(builder.newInstance(IAtom.class, "F"));
    mol.addBond(1, 2, Order.SINGLE);

    addExplicitHydrogens(mol);
    lpcheck.saturate(mol);

    DoubleResult result = ((DoubleResult) descriptor.calculate(mol.getAtom(1), mol).getValue());

    Assert.assertNotSame(0.0, result.doubleValue());
  }

  /** */
  @Test
  public void testNotCharged() throws Exception {

    IAtomContainer mol = builder.newInstance(IAtomContainer.class);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.getAtom(0).setFormalCharge(-1);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.addBond(0, 1, Order.DOUBLE);
    mol.addAtom(builder.newInstance(IAtom.class, "F"));
    mol.addBond(1, 2, Order.SINGLE);

    addExplicitHydrogens(mol);
    lpcheck.saturate(mol);

    DoubleResult result = ((DoubleResult) descriptor.calculate(mol.getAtom(0), mol).getValue());

    Assert.assertEquals(0.0, result.doubleValue(), 0.00001);
  }
  /**
   * A unit test for JUnit
   *
   * @throws Exception
   */
  @Test
  public void testStabilizationPlusChargeDescriptor2() throws Exception {

    IAtomContainer mol = builder.newInstance(IAtomContainer.class);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.getAtom(0).setFormalCharge(-1);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.getAtom(1).setFormalCharge(1);
    mol.addBond(0, 1, Order.SINGLE);
    mol.addAtom(builder.newInstance(IAtom.class, "F"));
    mol.addBond(1, 2, Order.SINGLE);

    addExplicitHydrogens(mol);
    lpcheck.saturate(mol);

    DoubleResult result = ((DoubleResult) descriptor.calculate(mol.getAtom(1), mol).getValue());

    Assert.assertNotSame(0.0, result.doubleValue());
  }

  /**
   * A unit test for JUnit
   *
   * @throws Exception
   */
  @Test
  public void testStabilizationComparative() throws Exception {

    IAtomContainer mol1 = builder.newInstance(IAtomContainer.class);
    mol1.addAtom(builder.newInstance(IAtom.class, "C"));
    mol1.addAtom(builder.newInstance(IAtom.class, "C"));
    mol1.getAtom(1).setFormalCharge(1);
    mol1.addBond(0, 1, Order.SINGLE);
    mol1.addAtom(builder.newInstance(IAtom.class, "C"));
    mol1.addBond(1, 2, Order.SINGLE);
    mol1.addAtom(builder.newInstance(IAtom.class, "O"));
    mol1.addBond(1, 3, Order.SINGLE);
    addExplicitHydrogens(mol1);
    lpcheck.saturate(mol1);

    DoubleResult result1 = ((DoubleResult) descriptor.calculate(mol1.getAtom(1), mol1).getValue());

    IAtomContainer mol2 = builder.newInstance(IAtomContainer.class);
    mol2.addAtom(builder.newInstance(IAtom.class, "C"));
    mol2.addAtom(builder.newInstance(IAtom.class, "C"));
    mol2.getAtom(1).setFormalCharge(1);
    mol2.addBond(0, 1, Order.SINGLE);
    mol2.addAtom(builder.newInstance(IAtom.class, "O"));
    mol2.addBond(1, 2, Order.SINGLE);
    addExplicitHydrogens(mol2);
    lpcheck.saturate(mol2);

    DoubleResult result2 = ((DoubleResult) descriptor.calculate(mol2.getAtom(1), mol2).getValue());

    IAtomContainer mol3 = builder.newInstance(IAtomContainer.class);
    mol3.addAtom(builder.newInstance(IAtom.class, "C"));
    mol3.addAtom(builder.newInstance(IAtom.class, "C"));
    mol3.getAtom(1).setFormalCharge(1);
    mol3.addBond(0, 1, Order.SINGLE);
    mol3.addAtom(builder.newInstance(IAtom.class, "C"));
    mol3.addBond(1, 2, Order.SINGLE);
    addExplicitHydrogens(mol3);
    lpcheck.saturate(mol3);

    DoubleResult result3 = ((DoubleResult) descriptor.calculate(mol3.getAtom(1), mol3).getValue());

    Assert.assertTrue(result3.doubleValue() < result2.doubleValue());
    Assert.assertTrue(result2.doubleValue() < result1.doubleValue());
  }
  /**
   * A unit test for JUnit with C=CCCl # C=CC[Cl+*]
   *
   * @cdk.inchi InChI=1/C3H7Cl/c1-2-3-4/h2-3H2,1H3
   */
  @Test
  public void testCompareIonized() throws Exception {

    IAtomContainer molA = builder.newInstance(IAtomContainer.class);
    molA.addAtom(builder.newInstance(IAtom.class, "C"));
    molA.addAtom(builder.newInstance(IAtom.class, "C"));
    molA.addBond(0, 1, IBond.Order.SINGLE);
    molA.addAtom(builder.newInstance(IAtom.class, "C"));
    molA.addBond(1, 2, IBond.Order.SINGLE);
    molA.addAtom(builder.newInstance(IAtom.class, "Cl"));
    molA.addBond(2, 3, IBond.Order.SINGLE);

    addExplicitHydrogens(molA);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molA);
    lpcheck.saturate(molA);

    double resultA =
        ((DoubleResult) descriptor.calculate(molA.getAtom(3), molA).getValue()).doubleValue();

    IAtomContainer molB = builder.newInstance(IAtomContainer.class);
    molB.addAtom(builder.newInstance(IAtom.class, "C"));
    molB.addAtom(builder.newInstance(IAtom.class, "C"));
    molB.addBond(0, 1, IBond.Order.SINGLE);
    molB.addAtom(builder.newInstance(IAtom.class, "C"));
    molB.addBond(1, 2, IBond.Order.SINGLE);
    molB.addAtom(builder.newInstance(IAtom.class, "Cl"));
    molB.getAtom(3).setFormalCharge(1);
    molB.addSingleElectron(3);
    molB.addLonePair(3);
    molB.addLonePair(3);
    molB.addBond(2, 3, IBond.Order.SINGLE);

    addExplicitHydrogens(molB);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molB);
    lpcheck.saturate(molB);

    Assert.assertEquals(1, molB.getAtom(3).getFormalCharge(), 0.00001);
    Assert.assertEquals(1, molB.getSingleElectronCount(), 0.00001);
    Assert.assertEquals(2, molB.getLonePairCount(), 0.00001);

    double resultB =
        ((DoubleResult) descriptor.calculate(molB.getAtom(3), molB).getValue()).doubleValue();

    Assert.assertNotSame(resultA, resultB);
  }
}
Exemplo n.º 11
0
/**
 * TestSuite that runs a test for the RadicalSiteHrBetaReaction.
 *
 * @cdk.module test-reaction
 */
public class RadicalSiteHrBetaReactionTest extends ReactionProcessTest {

  private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();

  /** The JUnit setup method */
  public RadicalSiteHrBetaReactionTest() throws Exception {
    setReaction(RadicalSiteHrBetaReaction.class);
  }

  /** The JUnit setup method */
  @Test
  public void testRadicalSiteHrBetaReaction() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();
    Assert.assertNotNull(type);
  }

  /**
   * A unit test suite for JUnit. Reaction:
   *
   * @return The test suite
   */
  @Test
  @Override
  public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();

    /* initiate */

    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    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(1, 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));
  }

  /**
   * create the compound
   *
   * @return The IAtomContainerSet
   */
  private IAtomContainerSet getExampleReactants() {
    IAtomContainerSet setOfReactants =
        DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);

    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    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);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.getAtom(3).setFormalCharge(1);
    molecule.addBond(2, 3, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(3, 4, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(4, 5, IBond.Order.SINGLE);
    try {
      addExplicitHydrogens(molecule);
    } catch (Exception e) {
      e.printStackTrace();
    }

    molecule.getAtom(3).setFormalCharge(0);
    molecule.addSingleElectron(new SingleElectron(molecule.getAtom(3)));

    try {
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
      makeSureAtomTypesAreRecognized(molecule);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    setOfReactants.addAtomContainer(molecule);
    return setOfReactants;
  }

  /**
   * Get the expected set of molecules.
   *
   * @return The IAtomContainerSet
   */
  private IAtomContainerSet getExpectedProducts() {
    IAtomContainerSet setOfProducts = builder.newInstance(IAtomContainerSet.class);

    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);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(2, 3, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(3, 4, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(4, 5, IBond.Order.SINGLE);
    try {
      addExplicitHydrogens(molecule);
    } catch (Exception e) {
      e.printStackTrace();
    }

    molecule.getAtom(0).setFormalCharge(0);
    molecule.addSingleElectron(new SingleElectron(molecule.getAtom(0)));

    try {
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
      makeSureAtomTypesAreRecognized(molecule);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    setOfProducts.addAtomContainer(molecule);
    return setOfProducts;
  }

  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testCDKConstants_REACTIVE_CENTER() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);

    /* manually put the reactive center */
    molecule.getAtom(3).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(6).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(5).setFlag(CDKConstants.REACTIVE_CENTER, true);

    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    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(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
  }

  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testMapping() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);

    /* automatic search of the center active */
    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);

    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);

    Assert.assertEquals(19, 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(6));
    Assert.assertEquals(mappedProductA2, product.getAtom(6));
    IAtom mappedProductA3 =
        (IAtom)
            ReactionManipulator.getMappedChemObject(
                setOfReactions.getReaction(0), molecule.getAtom(3));
    Assert.assertEquals(mappedProductA3, product.getAtom(3));
  }

  /**
   * Test to recognize if a IAtomContainer matcher correctly identifies the CDKAtomTypes.
   *
   * @param molecule The IAtomContainer to analyze
   * @throws CDKException
   */
  private void makeSureAtomTypesAreRecognized(IAtomContainer molecule) throws CDKException {

    Iterator<IAtom> atoms = molecule.atoms().iterator();
    CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(molecule.getBuilder());
    while (atoms.hasNext()) {
      IAtom nextAtom = atoms.next();
      Assert.assertNotNull(
          "Missing atom type for: " + nextAtom, matcher.findMatchingAtomType(molecule, nextAtom));
    }
  }
}
Exemplo n.º 12
0
public class TestIsomorphismTester extends TestCase {
  public LoggingTool logger;
  public SmartsParser sp = new SmartsParser();
  public SmartsManager man = new SmartsManager(SilentChemObjectBuilder.getInstance());
  public IsomorphismTester isoTester = new IsomorphismTester();

  // Helper variable where the results from match function is stored
  boolean boolResult;
  int mappingPosCount;

  public TestIsomorphismTester() {
    logger = new LoggingTool(this);
  }

  public static Test suite() {
    return new TestSuite(TestIsomorphismTester.class);
  }

  public void match(String smarts, String smiles) throws Exception {
    // Testing the algorithm via SmartsManager
    IMolecule mol = SmartsHelper.getMoleculeFromSmiles(smiles);
    man.setUseCDKIsomorphismTester(false);
    man.setQuery(smarts);
    boolResult = man.searchIn(mol);

    // Direct test of class IsomorphismTester
    IQueryAtomContainer query = sp.parse(smarts);
    sp.setNeededDataFlags();
    String errorMsg = sp.getErrorMessages();
    if (!errorMsg.equals("")) {
      System.out.println("Smarts Parser errors:\n" + errorMsg);
      return;
    }

    isoTester.setQuery(query);
    sp.setSMARTSData(mol);
    List<Integer> pos = isoTester.getIsomorphismPositions(mol);
    mappingPosCount = pos.size();
  }

  // ---------------------------------------------------------------------------------

  /** Tests from From http://www.daylight.com/dayhtml_tutorials/languages/smarts/index.html */
  public void testPropertyCharge1() throws Exception {
    match("[+1]", "[OH-].[Mg+2]");
    assertEquals(false, boolResult);
    assertEquals(0, mappingPosCount);
  }

  public void testPropertyCharge2() throws Exception {
    match("[+1]", "COCC(O)Cn1ccnc1[N+](=O)[O-]");
    assertEquals(true, boolResult);
    assertEquals(1, mappingPosCount);
  }

  public void testPropertyCharge3() throws Exception {
    match("[+1]", "[NH4+]");
    assertEquals(true, boolResult);
    assertEquals(1, mappingPosCount);
  }

  public void testPropertyCharge4() throws Exception {
    match("[+1]", "CN1C(=O)N(C)C(=O)C(N(C)C=N2)=C12");
    assertEquals(false, boolResult);
    assertEquals(0, mappingPosCount);
  }

  public void testPropertyCharge5() throws Exception {
    match("[+1]", "[Cl-].[Cl-].NC(=O)c2cc[n+](COC[n+]1ccccc1C=NO)cc2");
    assertEquals(true, boolResult);
    assertEquals(2, mappingPosCount);
  }

  public void testPropertyAromatic1() throws Exception {
    match("[a]", "c1cc(C)c(N)cc1");
    assertEquals(true, boolResult);
    assertEquals(6, mappingPosCount);
  }

  public void testPropertyAromatic2() throws Exception {
    match("[a]", "c1c(C)c(N)cnc1");
    assertEquals(true, boolResult);
    assertEquals(6, mappingPosCount);
  }

  public void testPropertyAromatic3() throws Exception {
    match("[a]", "c1(C)c(N)cco1");
    assertEquals(true, boolResult);
    assertEquals(5, mappingPosCount);
  }

  public void testPropertyAromatic4() throws Exception {
    match("[a]", "c1c(C)c(N)c[nH]1");
    assertEquals(true, boolResult);
    assertEquals(5, mappingPosCount);
  }

  public void testPropertyAromatic5() throws Exception {
    match("[a]", "n1cc(O)ccc1"); // On1ccccc1 is not recognized as aromatic
    assertEquals(true, boolResult);
    assertEquals(6, mappingPosCount);
  }

  public void testPropertyAromatic6() throws Exception {
    match("[a]", "[O-][n+]1ccccc1");
    assertEquals(true, boolResult);
    assertEquals(6, mappingPosCount);
  }

  public void testPropertyAromatic7() throws Exception {
    match("[a]", "c1ncccc1C1CCCN1C");
    assertEquals(true, boolResult);
    assertEquals(6, mappingPosCount);
  }

  public void testPropertyAromatic8() throws Exception {
    match("[a]", "c1ccccc1C(=O)OC2CC(N3C)CCC3C2C(=O)OC");
    assertEquals(true, boolResult);
    assertEquals(6, mappingPosCount);
  }

  public void testPropertyRing3() throws Exception {
    match("CC=1CC=1", "CC=1CC=1");
    assertEquals(true, boolResult);
    assertEquals(1, mappingPosCount);
  }

  public void testDoubleNonAromaticBond1() throws Exception {
    match("cc=c", "C1=CC=CC=C1C2=CC=CC=C2");
    assertEquals(false, boolResult);
  }

  public void testDoubleNonAromaticBond2() throws Exception {
    match("cc=c", "c1ccccc1c2ccccc2");
    assertEquals(false, boolResult);
  }

  // ----------------  Test recursive SMARTS -------------------

  public void testRecursiveSmarts4() throws Exception {
    match("[$(*O);$(*CC)]", "c1ncccc1C1CCCN1C");
    assertEquals(false, boolResult);
    // assertEquals(0, mappingPosCount);
  }

  public void testRecursiveSmarts5() throws Exception {
    match("[$(*O);$(*CC)]", "N12CCC36C1CC(C(C2)=CCOC4CC5=O)C4C3N5c7ccccc76");
    assertEquals(true, boolResult);
    // assertEquals(1, mappingPosCount);
  }

  public void testRecursiveSmarts6() throws Exception {
    match("[$([CX3]=[CX1]),$([CX3+]-[CX1-])]", "CN1C(=O)N(C)C(=O)C(N(C)C=N2)=C12");
    assertEquals(false, boolResult);
    // assertEquals(0, mappingPosCount);
  }
}