@Test
  public void testfp2() throws Exception {
    SmilesParser parser = new SmilesParser(NoNotificationChemObjectBuilder.getInstance());
    IFingerprinter printer = new MACCSFingerprinter();

    IMolecule mol1 = parser.parseSmiles("CC(N)CCCN");
    IMolecule mol2 = parser.parseSmiles("CC(N)CCC");
    IMolecule mol3 = parser.parseSmiles("CCCC");

    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol3);

    CDKHueckelAromaticityDetector.detectAromaticity(mol1);
    CDKHueckelAromaticityDetector.detectAromaticity(mol2);
    CDKHueckelAromaticityDetector.detectAromaticity(mol3);

    BitSet bs1 = printer.getFingerprint(mol1);
    BitSet bs2 = printer.getFingerprint(mol2);
    BitSet bs3 = printer.getFingerprint(mol3);

    Assert.assertFalse(bs1.get(124));
    Assert.assertFalse(bs2.get(124));
    Assert.assertFalse(bs3.get(124));

    Assert.assertFalse(FingerprinterTool.isSubset(bs1, bs2));
    Assert.assertTrue(FingerprinterTool.isSubset(bs2, bs3));
  }
Beispiel #2
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]"));
  }
  @Test
  public void testFingerprinter_int_int() throws java.lang.Exception {
    ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(1024);
    Assert.assertNotNull(fingerprinter);

    IAtomContainer mol = TestMoleculeFactory.makeIndole();
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    BitSet bs = fingerprinter.getBitFingerprint(mol).asBitSet();
    IAtomContainer frag1 = TestMoleculeFactory.makePyrrole();
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1);
    BitSet bs1 = fingerprinter.getBitFingerprint(frag1).asBitSet();
    Assert.assertTrue(FingerprinterTool.isSubset(bs, bs1));
  }
  @Test
  public void testGenerateFingerprintMultiphtalene() throws InvalidSmilesException, Exception {

    String smiles = "C1=CC2=CC=C3C4=CC5=CC6=CC=CC=C6C=C5C=C4C=CC3=C2C=C1";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
    ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024);
    BitSet fingerprint1;
    fingerprint1 = fingerprint.getBitFingerprint(molecule).asBitSet();
    org.junit.Assert.assertEquals(15, fingerprint1.cardinality());
  }
  /**
   * Calculates the eccentric connectivity
   *
   * @param container Parameter is the atom container.
   * @return An IntegerResult value representing the eccentric connectivity index
   */
  @TestMethod("testCalculate_IAtomContainer")
  public DescriptorValue calculate(IAtomContainer container) {
    IAtomContainer local = AtomContainerManipulator.removeHydrogens(container);

    int natom = local.getAtomCount();
    int[][] admat = AdjacencyMatrix.getMatrix(local);
    int[][] distmat = PathTools.computeFloydAPSP(admat);

    int eccenindex = 0;
    for (int i = 0; i < natom; i++) {
      int max = -1;
      for (int j = 0; j < natom; j++) {
        if (distmat[i][j] > max) max = distmat[i][j];
      }
      int degree = local.getConnectedBondsCount(i);
      eccenindex += max * degree;
    }
    IntegerResult retval = new IntegerResult(eccenindex);
    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        retval,
        getDescriptorNames(),
        null);
  }
  /**
   * 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;
  }
Beispiel #7
0
  @TestMethod("testCalculate_IAtomContainer")
  public DescriptorValue calculate(IAtomContainer container) {

    // removeHydrogens does a deep copy, so no need to clone
    IAtomContainer localAtomContainer = AtomContainerManipulator.removeHydrogens(container);
    CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(container.getBuilder());
    Iterator<IAtom> atoms = localAtomContainer.atoms().iterator();
    while (atoms.hasNext()) {
      IAtom atom = atoms.next();
      IAtomType type;
      try {
        type = matcher.findMatchingAtomType(localAtomContainer, atom);
        AtomTypeManipulator.configure(atom, type);
      } catch (Exception e) {
        return getDummyDescriptorValue(new CDKException("Error in atom typing: " + e.getMessage()));
      }
    }
    CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(container.getBuilder());
    try {
      hAdder.addImplicitHydrogens(localAtomContainer);
    } catch (CDKException e) {
      return getDummyDescriptorValue(
          new CDKException("Error in hydrogen addition: " + e.getMessage()));
    }

    List subgraph3 = order3(localAtomContainer);
    List subgraph4 = order4(localAtomContainer);
    List subgraph5 = order5(localAtomContainer);
    List subgraph6 = order6(localAtomContainer);

    double order3s = ChiIndexUtils.evalSimpleIndex(localAtomContainer, subgraph3);
    double order4s = ChiIndexUtils.evalSimpleIndex(localAtomContainer, subgraph4);
    double order5s = ChiIndexUtils.evalSimpleIndex(localAtomContainer, subgraph5);
    double order6s = ChiIndexUtils.evalSimpleIndex(localAtomContainer, subgraph6);

    double order3v, order4v, order5v, order6v;
    try {
      order3v = ChiIndexUtils.evalValenceIndex(localAtomContainer, subgraph3);
      order4v = ChiIndexUtils.evalValenceIndex(localAtomContainer, subgraph4);
      order5v = ChiIndexUtils.evalValenceIndex(localAtomContainer, subgraph5);
      order6v = ChiIndexUtils.evalValenceIndex(localAtomContainer, subgraph6);
    } catch (CDKException e) {
      return getDummyDescriptorValue(
          new CDKException("Error in substructure search: " + e.getMessage()));
    }
    DoubleArrayResult retval = new DoubleArrayResult();
    retval.add(order3s);
    retval.add(order4s);
    retval.add(order5s);
    retval.add(order6s);

    retval.add(order3v);
    retval.add(order4v);
    retval.add(order5v);
    retval.add(order6v);

    return new DescriptorValue(
        getSpecification(), getParameterNames(), getParameters(), retval, getDescriptorNames());
  }
  /**
   * 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);
  }
 @Test
 public void testRegression() throws Exception {
   IAtomContainer mol1 = TestMoleculeFactory.makeIndole();
   IAtomContainer mol2 = TestMoleculeFactory.makePyrrole();
   AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1);
   AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2);
   ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter();
   IBitFingerprint bs1 = fingerprinter.getBitFingerprint(mol1);
   Assert.assertEquals(
       "Seems the fingerprint code has changed. This will cause a number of other tests to fail too!",
       22,
       bs1.cardinality());
   IBitFingerprint bs2 = fingerprinter.getBitFingerprint(mol2);
   Assert.assertEquals(
       "Seems the fingerprint code has changed. This will cause a number of other tests to fail too!",
       11,
       bs2.cardinality());
 }
Beispiel #10
0
  public static void main(String[] args) throws Exception, CloneNotSupportedException, IOException {
    SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer mol1 = sp.parseSmiles("c1cccc(COC(=O)NC(CC(C)C)C(=O)NC(CCc2ccccc2)C(=O)COC)c1");
    IAtomContainer mol2 = sp.parseSmiles("c1cccc(COC(=O)NC(CC(C)C)C(=O)NCC#N)c1");
    CDKHueckelAromaticityDetector.detectAromaticity(mol1);
    CDKHueckelAromaticityDetector.detectAromaticity(mol2);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1);
    IAtomContainer mcs = getMcsAsNewContainer(mol1, mol2);
    MoleculeImage mi = new MoleculeImage(mcs);
    byte[] bytes = mi.getBytes(300, 300);
    FileOutputStream fos = new FileOutputStream("test.png");
    fos.write(bytes);

    int[][] map = getMcsAsAtomIndexMapping(mol1, mol2);
    for (int i = 0; i < map.length; i++) {
      System.out.println(map[i][0] + " <-> " + map[i][1]);
    }
  }
 @Test
 public void testFingerprinterBitSetSize() throws Exception {
   ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter(1024);
   Assert.assertNotNull(fingerprinter);
   IAtomContainer mol = TestMoleculeFactory.makeIndole();
   AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
   BitSet bs = fingerprinter.getBitFingerprint(mol).asBitSet();
   Assert.assertEquals(1024, bs.length()); // highest set bit
   Assert.assertEquals(1024, bs.size()); // actual bit set size
 }
  @Test
  public void testgetBitFingerprint_IAtomContainer() throws java.lang.Exception {
    ShortestPathFingerprinter fingerprinter = new ShortestPathFingerprinter();

    IAtomContainer mol = TestMoleculeFactory.makeIndole();
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    IBitFingerprint bs = fingerprinter.getBitFingerprint(mol);
    Assert.assertNotNull(bs);
    Assert.assertEquals(fingerprinter.getSize(), bs.size());
  }
  /**
   * This method calculates the ionization potential of an atom.
   *
   * @param atom The IAtom to ionize.
   * @param container Parameter is the IAtomContainer.
   * @return The ionization potential. Not possible the ionization.
   */
  @Override
  public DescriptorValue calculate(IAtom atom, IAtomContainer container) {
    double value = 0;
    // FIXME: for now I'll cache a few modified atomic properties, and restore them at the end of
    // this method
    String originalAtomtypeName = atom.getAtomTypeName();
    Integer originalNeighborCount = atom.getFormalNeighbourCount();
    Integer originalValency = atom.getValency();
    IAtomType.Hybridization originalHybrid = atom.getHybridization();
    Double originalBondOrderSum = atom.getBondOrderSum();
    Order originalMaxBondOrder = atom.getMaxBondOrder();

    if (!isCachedAtomContainer(container)) {
      try {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container);

        LonePairElectronChecker lpcheck = new LonePairElectronChecker();
        lpcheck.saturate(container);
      } catch (CDKException e) {
        return new DescriptorValue(
            getSpecification(),
            getParameterNames(),
            getParameters(),
            new DoubleResult(Double.NaN),
            getDescriptorNames(),
            e);
      }
    }

    try {
      value = IonizationPotentialTool.predictIP(container, atom);
    } catch (CDKException e) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new DoubleResult(Double.NaN),
          getDescriptorNames(),
          e);
    }
    // restore original props
    atom.setAtomTypeName(originalAtomtypeName);
    atom.setFormalNeighbourCount(originalNeighborCount);
    atom.setValency(originalValency);
    atom.setHybridization(originalHybrid);
    atom.setMaxBondOrder(originalMaxBondOrder);
    atom.setBondOrderSum(originalBondOrderSum);

    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        new DoubleResult(value),
        getDescriptorNames());
  }
Beispiel #14
0
  /** @cdk.inchi InChI=1/C4H5N/c1-2-4-5-3-1/h1-5H */
  @Test
  public void xtestPyrrole() throws Exception {
    IAtomContainer enol = new AtomContainer();

    // atom block
    IAtom atom1 = new Atom(Elements.CARBON);
    atom1.setHybridization(Hybridization.SP2);
    IAtom atom2 = new Atom(Elements.CARBON);
    atom2.setHybridization(Hybridization.SP2);
    IAtom atom3 = new Atom(Elements.CARBON);
    atom3.setHybridization(Hybridization.SP2);
    IAtom atom4 = new Atom(Elements.CARBON);
    atom4.setHybridization(Hybridization.SP2);
    IAtom atom5 = new Atom(Elements.NITROGEN);
    atom5.setHybridization(Hybridization.SP2);
    atom5.setImplicitHydrogenCount(1);

    // bond block
    IBond bond1 = new Bond(atom1, atom2);
    IBond bond2 = new Bond(atom2, atom3);
    IBond bond3 = new Bond(atom3, atom4);
    IBond bond4 = new Bond(atom4, atom5);
    IBond bond5 = new Bond(atom5, atom1);

    enol.addAtom(atom1);
    enol.addAtom(atom2);
    enol.addAtom(atom3);
    enol.addAtom(atom4);
    enol.addAtom(atom5);
    enol.addBond(bond1);
    enol.addBond(bond2);
    enol.addBond(bond3);
    enol.addBond(bond4);
    enol.addBond(bond5);

    // perceive atom types
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol);

    // now have the algorithm have a go at it
    enol = fbot.kekuliseAromaticRings(enol);
    Assert.assertNotNull(enol);
    // Assert.assertTrue(fbot.isOK(enol));

    // now check whether it did the right thing
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(0).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(1).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(2).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(3).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(4).getOrder());
    ;
  }
Beispiel #15
0
 private void fixHydrogenIsotopes(IAtomContainer molecule, IsotopeFactory isotopeFactory) {
   for (IAtom atom : AtomContainerManipulator.getAtomArray(molecule)) {
     if (atom instanceof IPseudoAtom) {
       IPseudoAtom pseudo = (IPseudoAtom) atom;
       if ("D".equals(pseudo.getLabel())) {
         IAtom newAtom = molecule.getBuilder().newInstance(IAtom.class, atom);
         newAtom.setSymbol("H");
         newAtom.setAtomicNumber(1);
         isotopeFactory.configure(newAtom, isotopeFactory.getIsotope("H", 2));
         AtomContainerManipulator.replaceAtomByAtom(molecule, atom, newAtom);
       } else if ("T".equals(pseudo.getLabel())) {
         IAtom newAtom = molecule.getBuilder().newInstance(IAtom.class, atom);
         newAtom.setSymbol("H");
         newAtom.setAtomicNumber(1);
         isotopeFactory.configure(newAtom, isotopeFactory.getIsotope("H", 3));
         AtomContainerManipulator.replaceAtomByAtom(molecule, atom, newAtom);
       }
     }
   }
 }
  /**
   * Test of ShortestPathFingerprinter method
   *
   * @throws InvalidSmilesException
   * @throws CDKException
   */
  @Test
  public void testGenerateFingerprintIsSubset() throws InvalidSmilesException, CDKException {

    String smilesT = "NC(=O)C1=C2C=CC(Br)=CC2=C(Cl)C=C1";
    String smilesQ = "CC1=C2C=CC(Br)=CC2=C(Cl)C=C1";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer moleculeQ = smilesParser.parseSmiles(smilesQ);
    IAtomContainer moleculeT = smilesParser.parseSmiles(smilesT);

    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(moleculeQ);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(moleculeT);

    ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024);
    BitSet fingerprintQ;
    BitSet fingerprintT;
    fingerprintQ = fingerprint.getBitFingerprint(moleculeQ).asBitSet();
    fingerprintT = fingerprint.getBitFingerprint(moleculeT).asBitSet();

    org.junit.Assert.assertTrue(FingerprinterTool.isSubset(fingerprintT, fingerprintQ));
  }
Beispiel #17
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);
 }
  /**
   * Test of ShortestPathFingerprinter method
   *
   * @throws InvalidSmilesException
   * @throws CDKException
   * @throws FileNotFoundException
   */
  @Test
  public void testGenerateFingerprintIsNotASubset1()
      throws InvalidSmilesException, CDKException, FileNotFoundException, FileNotFoundException {

    String smilesT = "O[C@H]1[C@H](O)[C@@H](O)[C@H](O)[C@H](O)[C@@H]1O";
    String smilesQ = "OC[C@@H](O)[C@@H](O)[C@H](O)[C@@H](O)C(O)=O";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    smilesParser.kekulise(false);
    IAtomContainer moleculeQ = smilesParser.parseSmiles(smilesQ);

    IAtomContainer moleculeT = smilesParser.parseSmiles(smilesT);

    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(moleculeQ);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(moleculeT);

    ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024);
    BitSet fingerprintQ;
    BitSet fingerprintT;
    fingerprintQ = fingerprint.getBitFingerprint(moleculeQ).asBitSet();
    fingerprintT = fingerprint.getBitFingerprint(moleculeT).asBitSet();
    org.junit.Assert.assertFalse(FingerprinterTool.isSubset(fingerprintT, fingerprintQ));
  }
  @Test
  public void testAtomPermutation2() throws CDKException {
    IAtomContainer pamine = TestMoleculeFactory.makeCyclopentane();
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(pamine);
    ShortestPathFingerprinter fp = new ShortestPathFingerprinter();
    IBitFingerprint bs1 = fp.getBitFingerprint(pamine);

    AtomContainerAtomPermutor acp = new AtomContainerAtomPermutor(pamine);
    while (acp.hasNext()) {
      IAtomContainer container = acp.next();
      IBitFingerprint bs2 = fp.getBitFingerprint(container);
      Assert.assertTrue(bs1.equals(bs2));
    }
  }
  /**
   * Test of ShortestPathFingerprinter method
   *
   * @throws InvalidSmilesException
   * @throws CDKException
   */
  @Test
  public void testGenerateFingerprint() throws InvalidSmilesException, CDKException {

    String smiles = "CCCCC1C(=O)N(N(C1=O)C1=CC=CC=C1)C1=CC=CC=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(125, fingerprint1.cardinality());
    org.junit.Assert.assertEquals(1024, fingerprint1.size());
  }
Beispiel #21
0
  /**
   * Layout all rings in the given RingSet that are connected to a given Ring
   *
   * @param rs The RingSet to be searched for rings connected to Ring
   * @param ring The Ring for which all connected rings in RingSet are to be layed out.
   */
  void placeConnectedRings(IRingSet rs, IRing ring, int handleType, double bondLength) {
    IRingSet connectedRings = rs.getConnectedRings(ring);
    IRing connectedRing;
    IAtomContainer sharedAtoms;
    int sac;
    Point2d oldRingCenter, sharedAtomsCenter, tempPoint;
    Vector2d tempVector, oldRingCenterVector, newRingCenterVector;

    //		logger.debug(rs.reportRingList(molecule));
    for (IAtomContainer container : connectedRings.atomContainers()) {
      connectedRing = (IRing) container;
      if (!connectedRing.getFlag(CDKConstants.ISPLACED)) {
        //				logger.debug(ring.toString(molecule));
        //				logger.debug(connectedRing.toString(molecule));
        sharedAtoms = AtomContainerManipulator.getIntersection(ring, connectedRing);
        sac = sharedAtoms.getAtomCount();
        logger.debug("placeConnectedRings-> connectedRing: " + (ring.toString()));
        if ((sac == 2 && handleType == FUSED)
            || (sac == 1 && handleType == SPIRO)
            || (sac > 2 && handleType == BRIDGED)) {
          sharedAtomsCenter = GeometryTools.get2DCenter(sharedAtoms);
          oldRingCenter = GeometryTools.get2DCenter(ring);
          tempVector = (new Vector2d(sharedAtomsCenter));
          newRingCenterVector = new Vector2d(tempVector);
          newRingCenterVector.sub(new Vector2d(oldRingCenter));
          oldRingCenterVector = new Vector2d(newRingCenterVector);
          logger.debug(
              "placeConnectedRing -> tempVector: "
                  + tempVector
                  + ", tempVector.length: "
                  + tempVector.length());
          logger.debug("placeConnectedRing -> bondCenter: " + sharedAtomsCenter);
          logger.debug(
              "placeConnectedRing -> oldRingCenterVector.length(): "
                  + oldRingCenterVector.length());
          logger.debug(
              "placeConnectedRing -> newRingCenterVector.length(): "
                  + newRingCenterVector.length());
          tempPoint = new Point2d(sharedAtomsCenter);
          tempPoint.add(newRingCenterVector);
          placeRing(connectedRing, sharedAtoms, sharedAtomsCenter, newRingCenterVector, bondLength);
          connectedRing.setFlag(CDKConstants.ISPLACED, true);
          placeConnectedRings(rs, connectedRing, handleType, bondLength);
        }
      }
    }
  }
  @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);
  }
  /**
   * set the active center for this molecule. The active center will be those which correspond with
   * [A*]-B=C .
   *
   * <pre>
   * A: Atom with single electron
   * -: Single bond
   * B: Atom
   * =: Double bond
   * C: Atom
   *  </pre>
   *
   * @param reactant The molecule to set the activity
   * @throws CDKException
   */
  private void setActiveCenters(IAtomContainer reactant) throws CDKException {
    if (AtomContainerManipulator.getTotalNegativeFormalCharge(reactant)
        != 0 /*|| AtomContainerManipulator.getTotalPositiveFormalCharge(reactant) != 0*/) return;
    Iterator<IAtom> atoms = reactant.atoms().iterator();
    while (atoms.hasNext()) {
      IAtom atomi = atoms.next();
      if (reactant.getConnectedSingleElectronsCount(atomi) == 1) {

        Iterator<IBond> bondis = reactant.getConnectedBondsList(atomi).iterator();

        while (bondis.hasNext()) {
          IBond bondi = bondis.next();

          if (bondi.getOrder() == IBond.Order.SINGLE) {

            IAtom atomj = bondi.getConnectedAtom(atomi);
            if ((atomj.getFormalCharge() == CDKConstants.UNSET ? 0 : atomj.getFormalCharge()) == 0
                && reactant.getConnectedSingleElectronsCount(atomj) == 0) {

              Iterator<IBond> bondjs = reactant.getConnectedBondsList(atomj).iterator();
              while (bondjs.hasNext()) {
                IBond bondj = bondjs.next();

                if (bondj.equals(bondi)) continue;

                if (bondj.getOrder() == IBond.Order.DOUBLE) {

                  IAtom atomk = bondj.getConnectedAtom(atomj);
                  if ((atomk.getFormalCharge() == CDKConstants.UNSET ? 0 : atomk.getFormalCharge())
                          == 0
                      && reactant.getConnectedSingleElectronsCount(atomk) == 0) {

                    atomi.setFlag(CDKConstants.REACTIVE_CENTER, true);
                    atomj.setFlag(CDKConstants.REACTIVE_CENTER, true);
                    atomk.setFlag(CDKConstants.REACTIVE_CENTER, true);
                    bondi.setFlag(CDKConstants.REACTIVE_CENTER, true);
                    bondj.setFlag(CDKConstants.REACTIVE_CENTER, true);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Beispiel #24
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);
  }
  /**
   * Get the Ethene structure.
   *
   * @return The IMolecule
   * @throws CDKException
   */
  private IMolecule getEthene() throws Exception {
    IMolecule molecule = builder.newMolecule();
    molecule.addAtom(builder.newAtom("C"));
    molecule.addAtom(builder.newAtom("C"));
    molecule.addBond(0, 1, IBond.Order.DOUBLE);
    molecule.addAtom(builder.newAtom("H"));
    molecule.addAtom(builder.newAtom("H"));
    molecule.addAtom(builder.newAtom("H"));
    molecule.addAtom(builder.newAtom("H"));
    molecule.addBond(0, 2, IBond.Order.SINGLE);
    molecule.addBond(0, 3, IBond.Order.SINGLE);
    molecule.addBond(1, 4, IBond.Order.SINGLE);
    molecule.addBond(1, 5, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

    LonePairElectronChecker lpcheck = new LonePairElectronChecker();
    lpcheck.saturate(molecule);
    return molecule;
  }
Beispiel #26
0
  @Test
  public void testLargeRingSystem() throws Exception {
    String smiles = "O=C1Oc6ccccc6(C(O)C1C5c2ccccc2CC(c3ccc(cc3)c4ccccc4)C5)";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

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

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    Assert.assertEquals(34, molecule.getAtomCount());

    // we should have 14 double bonds
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(13, doubleBondCount);
  }
Beispiel #27
0
  /** @cdk.bug 3506770 */
  @Test
  public void testLargeBioclipseUseCase() throws Exception {
    String smiles =
        "COc1ccc2[C@@H]3[C@H](COc2c1)C(C)(C)OC4=C3C(=O)C(=O)C5=C4OC(C)(C)[C@@H]6COc7cc(OC)ccc7[C@H]56";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

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

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    Assert.assertEquals(40, molecule.getAtomCount());

    // we should have 14 double bonds
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(10, doubleBondCount);
  }
Beispiel #28
0
  @Test
  public void checkUniqueMolecularDescriptorNames() throws Exception {
    DescriptorEngine engine = new DescriptorEngine(DescriptorEngine.MOLECULAR);
    List<DescriptorSpecification> specs = engine.getDescriptorSpecifications();

    // we work with a simple molecule with 3D coordinates
    String filename = "data/mdl/lobtest2.sdf";
    InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
    ISimpleChemObjectReader reader = new MDLV2000Reader(ins);
    ChemFile content = (ChemFile) reader.read(new ChemFile());
    List cList = ChemFileManipulator.getAllAtomContainers(content);
    IAtomContainer ac = (IAtomContainer) cList.get(0);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac);

    engine.process(ac);

    int ncalc = 0;
    List<String> descNames = new ArrayList<String>();
    for (DescriptorSpecification spec : specs) {
      DescriptorValue value = (DescriptorValue) ac.getProperty(spec);
      if (value == null) continue;
      ncalc++;
      String[] names = value.getNames();
      descNames.addAll(Arrays.asList(names));
    }

    List<String> dups = new ArrayList<String>();
    Set<String> uniqueNames = new HashSet<String>();
    for (String name : descNames) {
      if (!uniqueNames.add(name)) dups.add(name);
    }
    Assert.assertEquals(specs.size(), ncalc);
    Assert.assertEquals(descNames.size(), uniqueNames.size());
    if (dups.size() != 0) {
      System.out.println("Following names were duplicated");
      for (String dup : dups) {
        System.out.println("dup = " + dup);
      }
    }
  }
  /**
   * The method calculates the sigma electronegativity of a given atom It is needed to call the
   * addExplicitHydrogensToSatisfyValency method from the class tools.HydrogenAdder.
   *
   * @param atom The IAtom for which the DescriptorValue is requested
   * @param ac AtomContainer
   * @return return the sigma electronegativity
   */
  @TestMethod(value = "testCalculate_IAtomContainer")
  public DescriptorValue calculate(IAtom atom, IAtomContainer ac) {

    IAtomContainer clone;
    IAtom localAtom;
    try {
      clone = (IAtomContainer) ac.clone();
      localAtom = clone.getAtom(ac.getAtomNumber(atom));
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(clone);
    } catch (CDKException e) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new DoubleResult(Double.NaN),
          descriptorNames,
          e);
    } catch (CloneNotSupportedException e) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new DoubleResult(Double.NaN),
          descriptorNames,
          e);
    }

    if (maxIterations != -1 && maxIterations != 0)
      electronegativity.setMaxIterations(maxIterations);

    double result = electronegativity.calculateSigmaElectronegativity(clone, localAtom);

    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        new DoubleResult(result),
        descriptorNames);
  }
Beispiel #30
0
  /**
   * Prepare the target molecule for analysis.
   *
   * <p>We perform ring perception and aromaticity detection and set up the appropriate properties.
   * Right now, this function is called each time we need to do a query and this is inefficient.
   *
   * @throws CDKException if there is a problem in ring perception or aromaticity detection, which
   *     is usually related to a timeout in the ring finding code.
   */
  private void initializeMolecule() throws CDKException {
    // Code copied from
    // org.openscience.cdk.qsar.descriptors.atomic.AtomValenceDescriptor;
    Map<String, Integer> valencesTable = new HashMap<String, Integer>();
    valencesTable.put("H", 1);
    valencesTable.put("Li", 1);
    valencesTable.put("Be", 2);
    valencesTable.put("B", 3);
    valencesTable.put("C", 4);
    valencesTable.put("N", 5);
    valencesTable.put("O", 6);
    valencesTable.put("F", 7);
    valencesTable.put("Na", 1);
    valencesTable.put("Mg", 2);
    valencesTable.put("Al", 3);
    valencesTable.put("Si", 4);
    valencesTable.put("P", 5);
    valencesTable.put("S", 6);
    valencesTable.put("Cl", 7);
    valencesTable.put("K", 1);
    valencesTable.put("Ca", 2);
    valencesTable.put("Ga", 3);
    valencesTable.put("Ge", 4);
    valencesTable.put("As", 5);
    valencesTable.put("Se", 6);
    valencesTable.put("Br", 7);
    valencesTable.put("Rb", 1);
    valencesTable.put("Sr", 2);
    valencesTable.put("In", 3);
    valencesTable.put("Sn", 4);
    valencesTable.put("Sb", 5);
    valencesTable.put("Te", 6);
    valencesTable.put("I", 7);
    valencesTable.put("Cs", 1);
    valencesTable.put("Ba", 2);
    valencesTable.put("Tl", 3);
    valencesTable.put("Pb", 4);
    valencesTable.put("Bi", 5);
    valencesTable.put("Po", 6);
    valencesTable.put("At", 7);
    valencesTable.put("Fr", 1);
    valencesTable.put("Ra", 2);
    valencesTable.put("Cu", 2);
    valencesTable.put("Mn", 2);
    valencesTable.put("Co", 2);

    // do all ring perception
    AllRingsFinder arf = new AllRingsFinder();
    IRingSet allRings;
    try {
      allRings = arf.findAllRings(atomContainer);
    } catch (CDKException e) {
      logger.debug(e.toString());
      throw new CDKException(e.toString(), e);
    }

    // sets SSSR information
    SSSRFinder finder = new SSSRFinder(atomContainer);
    IRingSet sssr = finder.findEssentialRings();

    for (IAtom atom : atomContainer.atoms()) {

      // add a property to each ring atom that will be an array of
      // Integers, indicating what size ring the given atom belongs to
      // Add SSSR ring counts
      if (allRings.contains(atom)) { // it's in a ring
        atom.setFlag(CDKConstants.ISINRING, true);
        // lets find which ring sets it is a part of
        List<Integer> ringsizes = new ArrayList<Integer>();
        IRingSet currentRings = allRings.getRings(atom);
        int min = 0;
        for (int i = 0; i < currentRings.getAtomContainerCount(); i++) {
          int size = currentRings.getAtomContainer(i).getAtomCount();
          if (min > size) min = size;
          ringsizes.add(size);
        }
        atom.setProperty(CDKConstants.RING_SIZES, ringsizes);
        atom.setProperty(CDKConstants.SMALLEST_RINGS, sssr.getRings(atom));
      } else {
        atom.setFlag(CDKConstants.ISINRING, false);
      }

      // determine how many rings bonds each atom is a part of
      int hCount;
      if (atom.getImplicitHydrogenCount() == CDKConstants.UNSET) hCount = 0;
      else hCount = atom.getImplicitHydrogenCount();

      List<IAtom> connectedAtoms = atomContainer.getConnectedAtomsList(atom);
      int total = hCount + connectedAtoms.size();
      for (IAtom connectedAtom : connectedAtoms) {
        if (connectedAtom.getSymbol().equals("H")) {
          hCount++;
        }
      }
      atom.setProperty(CDKConstants.TOTAL_CONNECTIONS, total);
      atom.setProperty(CDKConstants.TOTAL_H_COUNT, hCount);

      if (valencesTable.get(atom.getSymbol()) != null) {
        int formalCharge =
            atom.getFormalCharge() == CDKConstants.UNSET ? 0 : atom.getFormalCharge();
        atom.setValency(valencesTable.get(atom.getSymbol()) - formalCharge);
      }
    }

    for (IBond bond : atomContainer.bonds()) {
      if (allRings.getRings(bond).getAtomContainerCount() > 0) {
        bond.setFlag(CDKConstants.ISINRING, true);
      }
    }

    for (IAtom atom : atomContainer.atoms()) {
      List<IAtom> connectedAtoms = atomContainer.getConnectedAtomsList(atom);

      int counter = 0;
      IAtom any;
      for (IAtom connectedAtom : connectedAtoms) {
        any = connectedAtom;
        if (any.getFlag(CDKConstants.ISINRING)) {
          counter++;
        }
      }
      atom.setProperty(CDKConstants.RING_CONNECTIONS, counter);
    }

    // check for atomaticity
    try {
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(atomContainer);
      CDKHueckelAromaticityDetector.detectAromaticity(atomContainer);
    } catch (CDKException e) {
      logger.debug(e.toString());
      throw new CDKException(e.toString(), e);
    }
  }