@Test
 public void testBuilder() {
   TetrahedralChirality chirality =
       new TetrahedralChirality(molecule.getAtom(1), ligands, Stereo.CLOCKWISE);
   Assert.assertNull(chirality.getBuilder());
   chirality.setBuilder(DefaultChemObjectBuilder.getInstance());
   Assert.assertEquals(DefaultChemObjectBuilder.getInstance(), chirality.getBuilder());
 }
 @Before
 public void setUp() {
   this.parser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
   this.builder = DefaultChemObjectBuilder.getInstance();
   mol = builder.newInstance(IAtomContainer.class);
   mol.addAtom(builder.newInstance(IAtom.class, "C"));
   mol.addAtom(builder.newInstance(IAtom.class, "C"));
   mol.addBond(0, 1, IBond.Order.SINGLE);
   molSig = new MoleculeSignature(mol);
 }
Exemple #3
0
 /** @cdk.bug 826942 */
 @Test
 public void testSFBug826942() throws Exception {
   SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
   IAtomContainer molecule = sp.parseSmiles("C1CCC2C(C1)C4CCC3(CCCCC23)(C4)");
   IRingSet ringSet = new SSSRFinder(molecule).findSSSR();
   Assert.assertEquals(4, ringSet.getAtomContainerCount());
 }
  /**
   * 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;
  }
Exemple #5
0
  /** @cdk.bug 1535055 */
  @Test
  public void testBug1535055() throws Exception {
    SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer mol = sp.parseSmiles("COC(=O)c1ccc2c(c1)c1ccccc1[nH]2");
    CDKHueckelAromaticityDetector.detectAromaticity(mol);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    SmilesGenerator sg = new SmilesGenerator();
    sg.setUseAromaticityFlag(true);
    String s1 = sg.createSMILES(mol);

    String filename = "data/cml/bug1535055.cml";
    InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
    CMLReader reader = new CMLReader(ins);
    IChemFile chemFile = (IChemFile) reader.read(new ChemFile());

    // test the resulting ChemFile content
    Assert.assertNotNull(chemFile);
    IAtomContainer mol2 = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
    CDKHueckelAromaticityDetector.detectAromaticity(mol2);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2);
    String s2 = sg.createSMILES(mol2);

    Assert.assertTrue(s1.contains("[nH]"));
    Assert.assertTrue(s2.contains("[nH]"));
  }
Exemple #6
0
 @Test
 public void testGetAtomContainerCount() throws Exception {
   SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
   IAtomContainer molecule = sp.parseSmiles("c1ccccc1");
   IRingSet ringSet = new SSSRFinder(molecule).findSSSR();
   Assert.assertEquals(1, ringSet.getAtomContainerCount());
 }
  /**
   * A unit test suite for JUnit for Ethene. Reaction: O=C-C-H => O(H)-C=C. Automatic looking for
   * active center.
   *
   * @cdk.inchi InChI=1/C2H4/c1-2/h1-2H2
   * @return The test suite
   */
  @Test
  public void testInitiate_IMoleculeSet_IMoleculeSet() throws Exception {

    IReactionProcess type = new AdductionProtonPBReaction();

    IMolecule molecule = getEthene();

    IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
    setOfReactants.addMolecule(molecule);

    /* 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(2, setOfReactions.getReactionCount());
    Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount());

    IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

    IMolecule molecule2 = getExpected();

    IQueryAtomContainer queryAtom =
        QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
    Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2, queryAtom));
  }
 @Override
 public MoleculeType convertFromStream(InputStream is) throws MSMLConversionException {
   ArrayList<IMolecule> sdfMolecules = new ArrayList<IMolecule>();
   boolean skip = true;
   IteratingMDLReader reader =
       new IteratingMDLReader(is, DefaultChemObjectBuilder.getInstance(), skip);
   while (reader.hasNext()) {
     IMolecule sdfMolecule = (IMolecule) reader.next();
     sdfMolecules.add(sdfMolecule);
   }
   MoleculeType converted = new MoleculeType();
   if (sdfMolecules.size() < 1) {
     throw new MSMLConversionException(
         "Cannot convert molecule(s) because MDL file (.mol or .sdf) is empty");
   } else if (sdfMolecules.size() == 1) {
     converted = convert(sdfMolecules.get(0));
   } else {
     converted = convert(sdfMolecules);
   }
   converted.setMoleculeClass(MoleculeClassType.MOLECULE_LIST);
   // set convention
   converted.setConvention("convention:molecular");
   // set the origin format
   converted.setOrigin(OriginType.SDF);
   return converted;
 }
Exemple #9
0
  public static IAtomContainer getMcsAsNewContainer(IAtomContainer mol1, IAtomContainer mol2)
      throws CDKException, CloneNotSupportedException {
    Isomorphism mcs = new Isomorphism(org.openscience.cdk.smsd.interfaces.Algorithm.DEFAULT, true);
    mcs.init(mol1, mol2, true, true);
    mcs.setChemFilters(true, true, true);

    mol1 = mcs.getReactantMolecule();
    mol2 = mcs.getProductMolecule();

    IAtomContainer mcsmolecule =
        DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class, mol1);

    List<IAtom> atomsToBeRemoved = new ArrayList<IAtom>();
    for (IAtom atom : mcsmolecule.atoms()) {
      int index = mcsmolecule.getAtomNumber(atom);
      if (!mcs.getFirstMapping().containsKey(index)) {
        atomsToBeRemoved.add(atom);
      }
    }

    for (IAtom atom : atomsToBeRemoved) {
      mcsmolecule.removeAtomAndConnectedElectronContainers(atom);
    }

    return mcsmolecule;
  }
 @Test
 public void testGetInstance() {
   Object builder = DefaultChemObjectBuilder.getInstance();
   Assert.assertNotNull(builder);
   Assert.assertTrue(builder instanceof IChemObjectBuilder);
   Assert.assertTrue(builder instanceof DefaultChemObjectBuilder);
 }
 @Test
 public void testAromaticAtomsCountDescriptor() throws java.lang.Exception {
   Object[] params = {true};
   descriptor.setParameters(params);
   SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
   IAtomContainer mol = sp.parseSmiles("CCOc1ccccc1"); // ethanol
   Assert.assertEquals(6, ((IntegerResult) descriptor.calculate(mol).getValue()).intValue());
 }
  public static IAtomContainer makeFragment4() {
    IAtomContainer mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
    mol.addAtom(new Atom("C")); // 0
    mol.addAtom(new Atom("C")); // 1

    mol.addBond(0, 1, IBond.Order.SINGLE); // 1
    return mol;
  }
 @Test
 public void testEmpty() throws Exception {
   IAtomContainer mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
   MoleculeSignature signature = new MoleculeSignature(mol);
   String signatureString = signature.toCanonicalString();
   String expected = "";
   Assert.assertEquals(expected, signatureString);
 }
  /**
   * Initiate process. It is needed to call the addExplicitHydrogensToSatisfyValency from the class
   * tools.HydrogenAdder.
   *
   * @param reactants reactants of the reaction
   * @param agents agents of the reaction (Must be in this case null)
   * @exception CDKException Description of the Exception
   */
  @TestMethod("testInitiate_IMoleculeSet_IMoleculeSet")
  public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException {

    logger.debug("initiate reaction: HeterolyticCleavagePBReaction");

    if (reactants.getMoleculeCount() != 1) {
      throw new CDKException("HeterolyticCleavagePBReaction only expects one reactant");
    }
    if (agents != null) {
      throw new CDKException("HeterolyticCleavagePBReaction don't expects agents");
    }

    IReactionSet setOfReactions =
        DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
    IMolecule reactant = reactants.getMolecule(0);

    /* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter()) setActiveCenters(reactant);

    Iterator<IBond> bondis = reactant.bonds().iterator();
    while (bondis.hasNext()) {
      IBond bondi = bondis.next();
      IAtom atom1 = bondi.getAtom(0);
      IAtom atom2 = bondi.getAtom(1);
      if (bondi.getFlag(CDKConstants.REACTIVE_CENTER)
          && bondi.getOrder() != IBond.Order.SINGLE
          && atom1.getFlag(CDKConstants.REACTIVE_CENTER)
          && atom2.getFlag(CDKConstants.REACTIVE_CENTER)
          && (atom1.getFormalCharge() == CDKConstants.UNSET ? 0 : atom1.getFormalCharge()) == 0
          && (atom2.getFormalCharge() == CDKConstants.UNSET ? 0 : atom2.getFormalCharge()) == 0
          && reactant.getConnectedSingleElectronsCount(atom1) == 0
          && reactant.getConnectedSingleElectronsCount(atom2) == 0) {

        /**/
        for (int j = 0; j < 2; j++) {

          ArrayList<IAtom> atomList = new ArrayList<IAtom>();
          if (j == 0) {
            atomList.add(atom1);
            atomList.add(atom2);
          } else {
            atomList.add(atom2);
            atomList.add(atom1);
          }
          ArrayList<IBond> bondList = new ArrayList<IBond>();
          bondList.add(bondi);

          IMoleculeSet moleculeSet = reactant.getBuilder().newInstance(IMoleculeSet.class);
          moleculeSet.addMolecule(reactant);
          IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
          if (reaction == null) continue;
          else setOfReactions.addReaction(reaction);
        }
      }
    }
    return setOfReactions;
  }
	public static IChemModel emptyModel() {
		final IChemModel chemModel = DefaultChemObjectBuilder.getInstance()
				.newInstance(IChemModel.class);
		chemModel.setMoleculeSet(chemModel.getBuilder().newInstance(
				IAtomContainerSet.class));
		chemModel.getMoleculeSet().addAtomContainer(
				chemModel.getBuilder().newInstance(IAtomContainer.class));
		return chemModel;
	}
 @Test
 public void testBug70() throws FileNotFoundException, CDKException {
   JPanelFixture jcppanel = applet.panel("appletframe");
   JChemPaintPanel panel = (JChemPaintPanel) jcppanel.target;
   applet.button("hexagon").click();
   applet.click();
   Point2d point = getAtomPoint(panel, 0);
   applet
       .panel("renderpanel")
       .robot
       .click(
           applet.panel("renderpanel").component(),
           new Point((int) point.x, (int) point.y),
           MouseButton.RIGHT_BUTTON,
           1);
   applet
       .panel("renderpanel")
       .robot
       .click(
           applet.panel("renderpanel").component(),
           new Point((int) point.x, (int) point.y),
           MouseButton.RIGHT_BUTTON,
           1);
   applet.menuItem("showACProperties").click();
   DialogFixture dialog = applet.dialog();
   JTextComponent textfield = dialog.robot.finder().find(JTextComponentMatcher.withName("Title"));
   textfield.setText("aaa");
   JButtonFixture okbutton =
       new JButtonFixture(
           dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("OK")));
   okbutton.click();
   applet.menuItem("save").click();
   dialog = applet.dialog();
   File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "test.mol");
   if (file.exists()) file.delete();
   JComboBox combobox =
       dialog
           .robot
           .finder()
           .find(new ComboBoxTextComponentMatcher("org.openscience.jchempaint.io.JCPFileFilter"));
   combobox.setSelectedItem(combobox.getItemAt(SAVE_AS_MOL_COMBOBOX_POS));
   JTextComponentFixture text = dialog.textBox();
   text.setText(file.toString());
   JButtonFixture savebutton =
       new JButtonFixture(
           dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
   savebutton.click();
   MDLReader reader = new MDLReader(new FileInputStream(file));
   IAtomContainer mol =
       (IAtomContainer)
           reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
   Assert.assertEquals("aaa", (String) mol.getProperty(CDKConstants.TITLE));
 }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testDefaultValidFalse() throws ClassNotFoundException, CDKException, Exception {

    IRule rule = new ChargeRule();

    IMolecularFormula formula = new MolecularFormula();
    formula.addIsotope(builder.newIsotope("C"), 2);
    formula.addIsotope(builder.newIsotope("H"), 200);
    formula.setCharge(1);

    Assert.assertEquals(0.0, rule.validate(formula), 0.0001);
  }
public class EquivalentClassPartitionerTest {

  public static final IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();

  @Test
  public void testQuinone() throws Exception {

    IAtomContainer mol = MoleculeFactory.makeQuinone();
    Assert.assertNotNull("Created molecule was null", mol);

    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    CDKHueckelAromaticityDetector.detectAromaticity(mol);

    EquivalentClassPartitioner partitioner = new EquivalentClassPartitioner(mol);
    int[] eqCl = partitioner.getTopoEquivClassbyHuXu(mol);
    Partition autP = ArrayToPartition.convert(eqCl, 1);

    Assert.assertEquals("Wrong number of equivalent classes", 3, autP.size());
    Partition expected = Partition.fromString("0,7|1,4|2,3,5,6");
    Assert.assertEquals("Wrong class assignment", expected, autP);
  }

  @Test
  public void one_four_cyclohexadiene() throws NoSuchAtomException {
    String acpString = "C0C1C2C3C4C5 0:1(2),0:5(1),1:2(1),2:3(1),3:4(2),4:5(1)";
    IAtomContainer cyclohexadiene = AtomContainerPrinter.fromString(acpString, builder);
    EquivalentClassPartitioner partitioner = new EquivalentClassPartitioner(cyclohexadiene);
    int[] eqCl = partitioner.getTopoEquivClassbyHuXu(cyclohexadiene);
    System.out.println(Arrays.toString(eqCl));
    System.out.println(ArrayToPartition.convert(eqCl, 1));
  }

  @Test
  public void four_H_pyran() throws NoSuchAtomException {
    String acpString = "C0C1C2C3C4O5 0:1(2),0:5(1),1:2(1),2:3(1),3:4(2),4:5(1)";
    IAtomContainer fourHpyran = AtomContainerPrinter.fromString(acpString, builder);
    EquivalentClassPartitioner partitioner = new EquivalentClassPartitioner(fourHpyran);
    int[] eqCl = partitioner.getTopoEquivClassbyHuXu(fourHpyran);
    System.out.println(Arrays.toString(eqCl));
    System.out.println(ArrayToPartition.convert(eqCl, 1));
  }

  @Test
  public void cuneane() throws NoSuchAtomException {
    String acpString =
        "C0C1C2C3C4C5C6C7 0:1(1),0:5(1),1:2(1),1:7(1),2:3(1),2:7(1),3:4(1),4:5(1),4:6(1),5:6(1),6:7(1)";
    IAtomContainer cuneane = AtomContainerPrinter.fromString(acpString, builder);
    EquivalentClassPartitioner partitioner = new EquivalentClassPartitioner(cuneane);
    int[] eqCl = partitioner.getTopoEquivClassbyHuXu(cuneane);
    System.out.println(Arrays.toString(eqCl));
    System.out.println(ArrayToPartition.convert(eqCl, 1));
  }
}
  @Test
  public void testVdWRadiusDescriptor()
      throws ClassNotFoundException, CDKException, java.lang.Exception {
    double[] testResult = {1.7};
    IAtomicDescriptor descriptor = new VdWRadiusDescriptor();
    SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IMolecule mol = sp.parseSmiles("NCCN(C)(C)");
    double retval =
        ((DoubleResult) descriptor.calculate(mol.getAtom(1), mol).getValue()).doubleValue();

    Assert.assertEquals(testResult[0], retval, 0.01);
  }
Exemple #20
0
  /**
   * @cdk.bug 1965254
   * @throws Exception
   */
  @Test
  public void testjunk() throws Exception {

    SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = sp.parseSmiles("COC1=CC2=C(C=C1)NC3=C2CCNC3");

    TemplateHandler3D template = TemplateHandler3D.getInstance();
    ModelBuilder3D mb3d = ModelBuilder3D.getInstance(template, "mm2");
    molecule = mb3d.generate3DCoordinates(molecule, true);
    DescriptorEngine engine = new DescriptorEngine(DescriptorEngine.MOLECULAR);

    engine.process(molecule);
  }
  @Test
  public void testGenerateFingerprintNaphthalene() throws InvalidSmilesException, Exception {

    String smiles = "C1=CC2=CC=CC=C2C=C1";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
    Aromaticity.cdkLegacy().apply(molecule);
    ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024);
    BitSet fingerprint1;
    fingerprint1 = fingerprint.getBitFingerprint(molecule).asBitSet();
    org.junit.Assert.assertEquals(8, fingerprint1.cardinality());
  }
 @Test
 public void testModelBuilder3D_CccccC() throws Exception {
   ModelBuilder3D mb3d = ModelBuilder3D.getInstance();
   String smile = "CccccC";
   SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
   IMolecule mol = sp.parseSmiles(smile);
   addExplicitHydrogens(mol);
   mol = mb3d.generate3DCoordinates(mol, false);
   for (int i = 0; i < mol.getAtomCount(); i++) {
     Assert.assertNotNull(mol.getAtom(i).getPoint3d());
   }
   checkAverageBondLength(mol);
   // logger.debug("Layout molecule with SMILE: "+smile);
 }
Exemple #23
0
  @Test
  public void testRingFlags1() throws Exception {
    SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = sp.parseSmiles("c1ccccc1");
    new SSSRFinder(molecule).findSSSR();

    int count = 0;
    Iterator atoms = molecule.atoms().iterator();
    while (atoms.hasNext()) {
      IAtom atom = (IAtom) atoms.next();
      if (atom.getFlag(CDKConstants.ISINRING)) count++;
    }
    Assert.assertEquals("All atoms in benzene were not marked as being in a ring", 6, count);
  }
Exemple #24
0
  /**
   * Checks if the given structures are isomorph.
   *
   * @param candidate1 the candidate1
   * @param candidate2 the candidate2
   * @return true, if is isomorph
   * @throws CDKException the CDK exception
   */
  public boolean isIsomorph(String candidate1, String candidate2) throws CDKException {
    IAtomContainer cand1 = null;
    IAtomContainer cand2 = null;

    if (hasAtomContainer) {
      cand1 = this.candidateToStructure.get(candidate1);
      cand2 = this.candidateToStructure.get(candidate2);
    } else {
      SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
      cand1 = sp.parseSmiles(candidatesToSmiles.get(candidate1));
      cand2 = sp.parseSmiles(candidatesToSmiles.get(candidate2));
    }

    return UniversalIsomorphismTester.isIsomorph(cand1, cand2);
  }
  @Test
  public void testModelBuilder3D_C1CCCCCCC1CC() throws Exception {
    Assume.assumeTrue(runSlowTests());

    ModelBuilder3D mb3d = ModelBuilder3D.getInstance();
    String smile = "C1CCCCCCC1CC";
    SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IMolecule mol = sp.parseSmiles(smile);
    addExplicitHydrogens(mol);
    mol = mb3d.generate3DCoordinates(mol, false);
    for (int i = 0; i < mol.getAtomCount(); i++) {
      Assert.assertNotNull(mol.getAtom(i).getPoint3d());
    }
    checkAverageBondLength(mol);
  }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testDefaultValidFalse_SetParam()
      throws ClassNotFoundException, CDKException, Exception {

    IRule rule = new ChargeRule();

    Object[] params = new Object[1];
    IMolecularFormula formula = new MolecularFormula();
    formula.addIsotope(builder.newIsotope("C"), 2);
    formula.addIsotope(builder.newIsotope("H"), 200);
    formula.setCharge(1);

    params[0] = -1.0;
    rule.setParameters(params);

    Assert.assertEquals(0.0, rule.validate(formula), 0.0001);
  }
Exemple #27
0
 /**
  * A unit test for JUnit
  *
  * @exception Exception Description of the Exception
  */
 @Test
 public void testResolveOverlap5() throws Exception {
   double overlapScore = 0;
   logger.debug("Test case with atom clash");
   IAtomContainer atomContainer =
       new SmilesParser(DefaultChemObjectBuilder.getInstance())
           .parseSmiles("OC4C(N2C1=C(C(=NC(=N1)SC)SC)C3=C2N=CN=C3N)OC(C4O)CO");
   StructureDiagramGenerator sdg = new StructureDiagramGenerator();
   sdg.setMolecule(new AtomContainer(atomContainer));
   sdg.generateCoordinates();
   atomContainer = sdg.getMolecule();
   OverlapResolver or = new OverlapResolver();
   overlapScore = or.resolveOverlap(atomContainer, null);
   // MoleculeViewer2D.display(new AtomContainer(atomContainer), true);
   Assert.assertEquals(0.0, overlapScore, 0.0001);
   logger.debug("End of test case with atom clash");
 }
  /**
   * Fixes Aromaticity of the molecule i.e. need to find rings and aromaticity again since added H's
   *
   * @param mol
   */
  @TestMethod("testFixAromaticity")
  public static void configure(IAtomContainer mol) {
    // need to find rings and aromaticity again since added H's

    IRingSet ringSet = null;
    try {
      AllRingsFinder arf = new AllRingsFinder();
      ringSet = arf.findAllRings(mol);
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      // figure out which atoms are in aromatic rings:
      CDKHydrogenAdder cdk = CDKHydrogenAdder.getInstance(DefaultChemObjectBuilder.getInstance());
      cdk.addImplicitHydrogens(mol);
      ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);

      CDKHueckelAromaticityDetector.detectAromaticity(mol);
      // figure out which rings are aromatic:
      RingSetManipulator.markAromaticRings(ringSet);
      // figure out which simple (non cycles) rings are aromatic:

      // only atoms in 6 membered rings are aromatic
      // determine largest ring that each atom is a part of

      for (int i = 0; i < mol.getAtomCount(); i++) {
        mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, false);
        jloop:
        for (int j = 0; j < ringSet.getAtomContainerCount(); j++) {
          // logger.debug(i+"\t"+j);
          IRing ring = (IRing) ringSet.getAtomContainer(j);
          if (!ring.getFlag(CDKConstants.ISAROMATIC)) {
            continue jloop;
          }
          boolean haveatom = ring.contains(mol.getAtom(i));
          // logger.debug("haveatom="+haveatom);
          if (haveatom && ring.getAtomCount() == 6) {
            mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #29
0
  @Test(timeout = 1000)
  public void testPyrrole() throws Exception {
    String smiles = "c2ccc3n([H])c1ccccc1c3(c2)";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.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);
  }
  public static IAtomContainer makeFragment3() {
    IAtomContainer mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
    mol.addAtom(new Atom("C")); // 0
    mol.addAtom(new Atom("C")); // 1
    mol.addAtom(new Atom("C")); // 2
    mol.addAtom(new Atom("C")); // 3
    mol.addAtom(new Atom("C")); // 4
    mol.addAtom(new Atom("C")); // 5
    mol.addAtom(new Atom("C")); // 6

    mol.addBond(0, 1, IBond.Order.SINGLE); // 1
    mol.addBond(0, 2, IBond.Order.SINGLE); // 2
    mol.addBond(0, 3, IBond.Order.SINGLE); // 3
    mol.addBond(0, 4, IBond.Order.SINGLE); // 4
    mol.addBond(3, 5, IBond.Order.DOUBLE); // 5
    mol.addBond(5, 6, IBond.Order.SINGLE); // 6
    return mol;
  }