Beispiel #1
0
  /**
   * Constructs an AtomContainer with a copy of the atoms and electronContainers of another
   * AtomContainer (A shallow copy, i.e., with the same objects as in the original AtomContainer).
   *
   * @param container An AtomContainer to copy the atoms and electronContainers from
   */
  public AtomContainer(IAtomContainer container) {
    this.atomCount = container.getAtomCount();
    this.bondCount = container.getBondCount();
    this.lonePairCount = container.getLonePairCount();
    this.singleElectronCount = container.getSingleElectronCount();
    this.atoms = new IAtom[this.atomCount];
    this.bonds = new IBond[this.bondCount];
    this.lonePairs = new ILonePair[this.lonePairCount];
    this.singleElectrons = new ISingleElectron[this.singleElectronCount];

    stereoElements = new HashSet<IStereoElement>(atomCount / 2);

    for (IStereoElement element : container.stereoElements()) {
      addStereoElement(element);
    }

    for (int f = 0; f < container.getAtomCount(); f++) {
      atoms[f] = container.getAtom(f);
      container.getAtom(f).addListener(this);
    }
    for (int f = 0; f < this.bondCount; f++) {
      bonds[f] = container.getBond(f);
      container.getBond(f).addListener(this);
    }
    for (int f = 0; f < this.lonePairCount; f++) {
      lonePairs[f] = container.getLonePair(f);
      container.getLonePair(f).addListener(this);
    }
    for (int f = 0; f < this.singleElectronCount; f++) {
      singleElectrons[f] = container.getSingleElectron(f);
      container.getSingleElectron(f).addListener(this);
    }
  }
Beispiel #2
0
  /** Checks if the ringSet (created by SSSR) contains rings with exactly the same atoms. */
  static boolean checkForDuplicateRingsInSet(IRingSet ringset) {
    // Make a list of rings
    List<IAtomContainer> ringList = new ArrayList<IAtomContainer>();
    for (IAtomContainer atCont : ringset.atomContainers()) {
      ringList.add(atCont);
    }
    // Outer loop over rings
    for (IAtomContainer ring : ringList) {
      // Inner loop over rings
      for (IAtomContainer otherRing : ringList) {
        if (otherRing.hashCode() != ring.hashCode()
            && otherRing.getAtomCount() == ring.getAtomCount()) {

          // check if the two rings have all the same atoms in them -
          // this should not happen (="duplicate" rings)
          boolean sameAtoms = true;
          DUP_LOOP:
          for (IAtom at : ring.atoms()) {
            if (!otherRing.contains(at)) {
              sameAtoms = false;
              break DUP_LOOP;
            }
          }
          if (sameAtoms) {
            return true;
          }
        }
      }
    }
    return false;
  }
 /**
  * Procedure required by the CDOInterface. This function is only supposed to be called by the JCFL
  * library
  */
 public void endObject(String objectType) {
   logger.debug("END: " + objectType);
   if (objectType.equals("Molecule")) {
     eventReader.fireFrameRead();
     clearData();
   } else if (objectType.equals("Atom")) {
     currentMolecule.addAtom(currentAtom);
   } else if (objectType.equals("Bond")) {
     logger.debug("Bond(" + bond_id + "): " + bond_a1 + ", " + bond_a2 + ", " + bond_order);
     if (bond_a1 > currentMolecule.getAtomCount() || bond_a2 > currentMolecule.getAtomCount()) {
       logger.error(
           "Cannot add bond between at least one non-existant atom: "
               + bond_a1
               + " and "
               + bond_a2);
     } else {
       IAtom a1 = currentMolecule.getAtom(bond_a1);
       IAtom a2 = currentMolecule.getAtom(bond_a2);
       IBond b = builder.newBond(a1, a2, bond_order);
       if (bond_id != null) b.setID(bond_id);
       if (bond_stereo != -99) {
         b.setStereo(bond_stereo);
       }
       currentMolecule.addBond(b);
     }
   }
 }
  /**
   * Generates a compatibility graph between two molecules
   *
   * @param source
   * @param target
   * @param shouldMatchBonds
   * @param shouldMatchRings
   * @param matchAtomType
   * @throws java.io.IOException
   */
  public GenerateCompatibilityGraph(
      IAtomContainer source,
      IAtomContainer target,
      boolean shouldMatchBonds,
      boolean shouldMatchRings,
      boolean matchAtomType)
      throws IOException {
    this.shouldMatchRings = shouldMatchRings;
    this.shouldMatchBonds = shouldMatchBonds;
    this.matchAtomType = matchAtomType;
    this.source = source;
    this.target = target;
    compGraphNodes = new ArrayList<>();
    compGraphNodesCZero = new ArrayList<>();
    cEdges = Collections.synchronizedList(new ArrayList<Integer>());
    dEdges = Collections.synchronizedList(new ArrayList<Integer>());

    /*
    Generate all possible graphs when no ring match or atom type is required
    */
    /*
    Modification for AAM only
    */
    if ((!shouldMatchBonds || !matchAtomType)
        && source.getAtomCount() > 30
        && target.getAtomCount() > 30) {
      compatibilityGraphNodesIfCEdgeIsZero();
      compatibilityGraphCEdgeZero();
      clearCompGraphNodesCZero();
    } else {
      //        System.out.println("compatibilityGraphNodes ");
      compatibilityGraphNodes();
      //        System.out.println("compatibilityGraph ");
      compatibilityGraph();
      //        System.out.println("c-edges " + getCEgdes().size());
      //        System.out.println("d-edges " + getDEgdes().size());

      if (getCEdgesSize() == 0) {
        clearCompGraphNodes();

        clearCEgdes();
        clearDEgdes();

        resetCEdgesSize();
        resetDEdgesSize();

        compatibilityGraphNodesIfCEdgeIsZero();
        compatibilityGraphCEdgeZero();
        clearCompGraphNodesCZero();
      }
    }
  }
Beispiel #5
0
  /**
   * Place hydrogens connected to the provided atom <i>atom</i> using the specified
   * <i>bondLength</i>.
   *
   * @param container atom container
   * @param bondLength bond length to user
   * @throws IllegalArgumentException thrown if the <i>atom</i> or <i>container</i> was null or the
   *     atom has connected atoms which have not been placed.
   */
  @TestMethod("testNoConnections,testNullContainer,unplacedNonHydrogen")
  public void placeHydrogens2D(IAtomContainer container, IAtom atom, double bondLength) {

    if (container == null)
      throw new IllegalArgumentException("cannot place hydrogens, no container provided");
    if (atom.getPoint2d() == null)
      throw new IllegalArgumentException("cannot place hydrogens on atom without coordinates");

    logger.debug(
        "placing hydrogens connected to atom ", atom.getSymbol(),
        ": ", atom.getPoint2d());
    logger.debug("bond length", bondLength);

    AtomPlacer atomPlacer = new AtomPlacer();
    atomPlacer.setMolecule(container);

    List<IAtom> connected = container.getConnectedAtomsList(atom);
    IAtomContainer placed = container.getBuilder().newInstance(IAtomContainer.class);
    IAtomContainer unplaced = container.getBuilder().newInstance(IAtomContainer.class);

    // divide connected atoms into those which are have and haven't been placed
    for (final IAtom conAtom : connected) {
      if (conAtom.getPoint2d() == null) {
        if (conAtom.getSymbol().equals("H")) {
          unplaced.addAtom(conAtom);
        } else {
          throw new IllegalArgumentException(
              "cannot place hydrogens, atom has connected" + " non-hydrogens without coordinates");
        }
      } else {
        placed.addAtom(conAtom);
      }
    }

    logger.debug("Atom placement before procedure:");
    logger.debug("Centre atom ", atom.getSymbol(), ": ", atom.getPoint2d());
    for (int i = 0; i < unplaced.getAtomCount(); i++) {
      logger.debug("H-" + i, ": ", unplaced.getAtom(i).getPoint2d());
    }

    Point2d centerPlacedAtoms = GeometryTools.get2DCenter(placed);
    atomPlacer.distributePartners(atom, placed, centerPlacedAtoms, unplaced, bondLength);

    logger.debug("Atom placement after procedure:");
    logger.debug("Centre atom ", atom.getSymbol(), ": ", atom.getPoint2d());
    for (int i = 0; i < unplaced.getAtomCount(); i++) {
      logger.debug("H-" + i, ": ", unplaced.getAtom(i).getPoint2d());
    }
  }
Beispiel #6
0
  public void timeFile(File dir, String filename) throws CDKException, IOException {
    IAtomContainer atomContainer = readFile(new File(dir, filename));
    long start;

    start = System.currentTimeMillis();
    EquivalentClassPartitioner it = new EquivalentClassPartitioner(atomContainer);
    int equivalentClass[] = it.getTopoEquivClassbyHuXu(atomContainer);
    Partition huXuPartition = ArrayToPartition.convert(equivalentClass, 1);
    long elapsedHuXu = System.currentTimeMillis() - start;

    start = System.currentTimeMillis();
    AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner();
    refiner.refine(atomContainer);
    Partition refinedPartition = refiner.getAutomorphismPartition();
    long elapsedRef = System.currentTimeMillis() - start;
    long order = refiner.getAutomorphismGroup().order();

    boolean partitionsEqual = refinedPartition.equals(huXuPartition);

    System.out.println(
        filename
            + "\t"
            + atomContainer.getAtomCount()
            + "\t"
            + elapsedRef
            + "\t"
            + elapsedHuXu
            + "\t"
            + order
            + "\t"
            + refinedPartition.size()
            + "\t"
            + partitionsEqual);
  }
Beispiel #7
0
  void executeSequence(boolean stopAtFirstMapping) {
    isomorphismFound = false;
    stack.clear();

    // Initial nodes
    QuerySequenceElement el = sequence.get(0);
    for (int k = 0; k < target.getAtomCount(); k++) {
      IAtom at = target.getAtom(k);
      if (el.center.matches(at)) {
        Node node = new Node();
        node.sequenceElNum = 0;
        node.nullifyAtoms(query.getAtomCount());
        node.atoms[el.centerNum] = at;
        stack.push(node);
      }
    }

    // Expanding the tree of all possible mappings
    if (stopAtFirstMapping) {
      while (!stack.isEmpty()) {
        expandNode(stack.pop());
        if (isomorphismFound) break;
      }
    } else {
      while (!stack.isEmpty()) expandNode(stack.pop());
    }
  }
Beispiel #8
0
  /**
   * If no isomorphism is found the result is empty vector
   *
   * @param container
   * @return
   */
  public List<List<IAtom>> getAllIsomorphismMappings(IAtomContainer container) {
    if (query == null) return null;
    target = container;
    FlagStoreIsomorphismNode = true;
    isomorphismNodes.clear();
    List<List<IAtom>> result = new ArrayList<List<IAtom>>();

    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) {
          List<IAtom> v = new ArrayList<IAtom>();
          v.add(target.getAtom(i));
          result.add(v);
        }
      }
      return result;
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    executeSequence(false);

    if (isomorphismFound) {
      // Getting the data from the all stored Nodes
      for (int k = 0; k < isomorphismNodes.size(); k++) {
        Node node = isomorphismNodes.get(k);
        List<IAtom> v = new ArrayList<IAtom>();
        for (int i = 0; i < node.atoms.length; i++) v.add(node.atoms[i]);
        result.add(v);
      }
    }
    return result;
  }
  @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]));
  }
  /**
   * 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);
  }
Beispiel #11
0
  /**
   * Adds all atoms and electronContainers of a given atomcontainer to this container.
   *
   * @param atomContainer The atomcontainer to be added
   */
  public void add(IAtomContainer atomContainer) {
    for (int f = 0; f < atomContainer.getAtomCount(); f++) {
      if (!contains(atomContainer.getAtom(f))) {
        addAtom(atomContainer.getAtom(f));
      }
    }
    for (int f = 0; f < atomContainer.getBondCount(); f++) {
      if (!contains(atomContainer.getBond(f))) {
        addBond(atomContainer.getBond(f));
      }
    }
    for (int f = 0; f < atomContainer.getLonePairCount(); f++) {
      if (!contains(atomContainer.getLonePair(f))) {
        addLonePair(atomContainer.getLonePair(f));
      }
    }
    for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) {
      if (!contains(atomContainer.getSingleElectron(f))) {
        addSingleElectron(atomContainer.getSingleElectron(f));
      }
    }

    for (IStereoElement se : atomContainer.stereoElements()) stereoElements.add(se);

    notifyChanged();
  }
Beispiel #12
0
  /**
   * This function returns null if no isomorphism is found
   *
   * @param container
   * @return
   */
  public List<IAtom> getIsomorphismMapping(IAtomContainer container) {
    if (query == null) return null;
    target = container;
    FlagStoreIsomorphismNode = true;
    isomorphismNodes.clear();

    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) {
          List<IAtom> v = new ArrayList<IAtom>();
          v.add(target.getAtom(i));
          return (v);
        }
      }
      return null;
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    executeSequence(true);

    if (isomorphismFound) {
      // Getting the data from the Node
      Node node = isomorphismNodes.get(0);
      List<IAtom> v = new ArrayList<IAtom>();
      for (int i = 0; i < node.atoms.length; i++) v.add(node.atoms[i]);

      return (v);
    } else return (null);
  }
Beispiel #13
0
  /**
   * Performs the pharmacophore matching.
   *
   * @param atomContainer The target molecule. Must have 3D coordinates
   * @param initializeTarget If <i>true</i>, the target molecule specified in the first argument
   *     will be analyzed to identify matching pharmacophore groups. If <i>false</i> this is not
   *     performed. The latter case is only useful when dealing with conformers since for a given
   *     molecule, all conformers will have the same pharmacophore groups and only the constraints
   *     will change from one conformer to another.
   * @return true is the target molecule contains the query pharmacophore
   * @throws org.openscience.cdk.exception.CDKException if the query pharmacophore was not set or
   *     the query is invalid or if the molecule does not have 3D coordinates
   */
  public boolean matches(IAtomContainer atomContainer, boolean initializeTarget)
      throws CDKException {
    if (!GeometryUtil.has3DCoordinates(atomContainer))
      throw new CDKException("Molecule must have 3D coordinates");
    if (pharmacophoreQuery == null)
      throw new CDKException("Must set the query pharmacophore before matching");
    if (!checkQuery(pharmacophoreQuery))
      throw new CDKException(
          "A problem in the query. Make sure all pharmacophore groups of the same symbol have the same same SMARTS");
    String title = (String) atomContainer.getProperty(CDKConstants.TITLE);

    if (initializeTarget) pharmacophoreMolecule = getPharmacophoreMolecule(atomContainer);
    else {
      // even though the atoms comprising the pcore groups are
      // constant, their coords will differ, so we need to make
      // sure we get the latest set of effective coordinates
      for (IAtom iAtom : pharmacophoreMolecule.atoms()) {
        PharmacophoreAtom patom = (PharmacophoreAtom) iAtom;
        List<Integer> tmpList = new ArrayList<Integer>();
        for (int idx : patom.getMatchingAtoms()) tmpList.add(idx);
        Point3d coords = getEffectiveCoordinates(atomContainer, tmpList);
        patom.setPoint3d(coords);
      }
    }

    if (pharmacophoreMolecule.getAtomCount() < pharmacophoreQuery.getAtomCount()) {
      logger.debug("Target [" + title + "] did not match the query SMARTS. Skipping constraints");
      return false;
    }

    mappings = Pattern.findSubstructure(pharmacophoreQuery).matchAll(pharmacophoreMolecule);

    // XXX: doing one search then discarding
    return mappings.atLeast(1);
  }
Beispiel #14
0
  @Test
  public void napthaleneSkeletonHeightTest() {
    IAtomContainer napthalene = builder.newInstance(IAtomContainer.class);
    for (int i = 0; i < 10; i++) {
      napthalene.addAtom(builder.newInstance(IAtom.class, "C"));
    }
    napthalene.addBond(0, 1, IBond.Order.SINGLE);
    napthalene.addBond(0, 5, IBond.Order.SINGLE);
    napthalene.addBond(1, 2, IBond.Order.SINGLE);
    napthalene.addBond(1, 6, IBond.Order.SINGLE);
    napthalene.addBond(2, 3, IBond.Order.SINGLE);
    napthalene.addBond(2, 9, IBond.Order.SINGLE);
    napthalene.addBond(3, 4, IBond.Order.SINGLE);
    napthalene.addBond(4, 5, IBond.Order.SINGLE);
    napthalene.addBond(6, 7, IBond.Order.SINGLE);
    napthalene.addBond(7, 8, IBond.Order.SINGLE);
    napthalene.addBond(8, 9, IBond.Order.SINGLE);

    MoleculeSignature molSig = new MoleculeSignature(napthalene);
    int height = 2;
    Map<String, Orbit> orbits = new HashMap<String, Orbit>();
    for (int i = 0; i < napthalene.getAtomCount(); i++) {
      String signatureString = molSig.signatureStringForVertex(i, height);
      Orbit orbit;
      if (orbits.containsKey(signatureString)) {
        orbit = orbits.get(signatureString);
      } else {
        orbit = new Orbit(signatureString, height);
        orbits.put(signatureString, orbit);
      }
      orbit.addAtom(i);
    }
    Assert.assertEquals(3, orbits.size());
  }
Beispiel #15
0
 public int findFirstAtomIndexForSymbol(IAtomContainer container, String symbol) {
   for (int i = 0; i < container.getAtomCount(); i++) {
     if (container.getAtom(i).getSymbol().equals(symbol)) {
       return i;
     }
   }
   return -1;
 }
Beispiel #16
0
 /**
  * Helper method, used to help construct a configuration.
  *
  * @param atom
  * @param container
  * @return the array position of atom in container
  */
 private int getAtomPosition(IAtom atom, IAtomContainer container) {
   for (int i = 0; i < container.getAtomCount(); i++) {
     if (atom.equals(container.getAtom(i))) {
       return i;
     }
   }
   return -1;
 }
  /**
   * compGraphNodesCZero is used to build up of the edges of the compatibility graph
   *
   * @return
   * @throws IOException
   */
  private Integer compatibilityGraphNodesIfCEdgeIsZero() throws IOException {

    int count_nodes = 1;
    List<String> list = new ArrayList<>();
    compGraphNodesCZero = new ArrayList<>(); // Initialize the compGraphNodesCZero List
    LabelContainer labelContainer = LabelContainer.getInstance();
    compGraphNodes.clear();

    for (int i = 0; i < source.getAtomCount(); i++) {
      for (int j = 0; j < target.getAtomCount(); j++) {
        IAtom atom1 = source.getAtom(i);
        IAtom atom2 = target.getAtom(j);

        // You can also check object equal or charge, hydrogen count etc
        if ((atom1 instanceof IQueryAtom)
            && ((IQueryAtom) atom1).matches(atom2)
            && !list.contains(i + "_" + j)) {
          compGraphNodesCZero.add(i);
          compGraphNodesCZero.add(j);
          compGraphNodesCZero.add(labelContainer.getLabelID(atom2.getSymbol())); // i.e C is label 1
          compGraphNodesCZero.add(count_nodes);
          compGraphNodes.add(i);
          compGraphNodes.add(j);
          compGraphNodes.add(count_nodes);
          count_nodes += 1;
          list.add(i + "_" + j);
        } else if (atom1.getSymbol().equalsIgnoreCase(atom2.getSymbol())
            && !list.contains(i + "_" + j)) {
          compGraphNodesCZero.add(i);
          compGraphNodesCZero.add(j);
          compGraphNodesCZero.add(labelContainer.getLabelID(atom1.getSymbol())); // i.e C is label 1
          compGraphNodesCZero.add(count_nodes);
          compGraphNodes.add(i);
          compGraphNodes.add(j);
          compGraphNodes.add(count_nodes);
          count_nodes += 1;
          list.add(i + "_" + j);
        }
      }
    }
    list.clear();
    return count_nodes;
  }
Beispiel #18
0
 /**
  * Validates that the SSSR has found the expected number of rings of a particular size.
  *
  * @param ringSet constructed by SSSR.
  * @param ringSizeForCounting particular ring size to count
  * @param expectedNumOfRings the expected number of rings
  */
 private void ringCount(IRingSet ringSet, int ringSizeForCounting, int expectedNumOfRings) {
   int ringCount = 0;
   for (IAtomContainer ring : ringSet.atomContainers()) {
     if (ring.getAtomCount() == ringSizeForCounting) {
       ringCount++;
     }
   }
   Assert.assertTrue(
       "Counting rings of size " + ringSizeForCounting, expectedNumOfRings == ringCount);
 }
Beispiel #19
0
 /**
  * Creates a bucky ball molecule.
  *
  * @return bucky ball molecule
  */
 private IAtomContainer createBuckyBall() throws CDKException {
   IAtomContainer molecule = null;
   String filename = "data/mdl/buckyball.mol";
   InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
   MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
   molecule = (IAtomContainer) reader.read(new AtomContainer());
   Assert.assertTrue("Atom count is 60 ", molecule.getAtomCount() == 60);
   Assert.assertTrue("Bond count is 90 ", molecule.getBondCount() == 90);
   return molecule;
 }
Beispiel #20
0
  public InChIMoleculeCheckerResult checkMolecule(IAtomContainer mol) {
    InChIMoleculeCheckerResult res = new InChIMoleculeCheckerResult();

    res.emptyMol = (mol.getAtomCount() == 0);
    res.bondNull = checkForNullBonds(mol);
    res.atomNull = checkForNullAtoms(mol);
    res.genericAtom = checkForGenericAtoms(mol);

    return res;
  }
Beispiel #21
0
 private List<Bounds> generate(List<IAtomContainer> mols, RendererModel model, int atomNum)
     throws CDKException {
   List<Bounds> elems = new ArrayList<>();
   int num = 0;
   for (IAtomContainer mol : mols) {
     elems.add(new Bounds(generate(mol, model, atomNum)));
     atomNum += mol.getAtomCount();
   }
   return elems;
 }
 public String toSMILES() {
   if ("".equals(smiles) && atomContainer instanceof IMolecule) {
     if (atomContainer.getAtomCount() < 100) {
       SmilesGenerator sg = new SmilesGenerator();
       smiles = sg.createSMILES((IMolecule) atomContainer);
     } else {
       logger.warn("Not generating SMILES. " + "DBMolecule " + name + " has too many atoms.");
     }
   }
   return smiles;
 }
Beispiel #23
0
 boolean singleAtomIsomorphism() {
   SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
   isomorphismFound = false;
   for (int i = 0; i < target.getAtomCount(); i++) {
     if (qa.matches(target.getAtom(i))) {
       isomorphismFound = true;
       break;
     }
   }
   return (isomorphismFound);
 }
Beispiel #24
0
  public List<Integer> getIsomorphismPositions(IAtomContainer container) {
    target = container;
    FlagStoreIsomorphismNode = false;
    isomorphismNodes.clear();

    List<Integer> v = new ArrayList<Integer>();
    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) v.add(new Integer(i));
      }
      return (v);
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    for (int i = 0; i < target.getAtomCount(); i++) {
      executeSequenceAtPos(i);
      if (isomorphismFound) v.add(new Integer(i));
    }
    return (v);
  }
Beispiel #25
0
  /**
   * Positions the aliphatic substituents of a ring system
   *
   * @param rs The RingSystem for which the substituents are to be laid out
   * @return A list of atoms that where laid out
   */
  public IAtomContainer placeRingSubstituents(IRingSet rs, double bondLength) {
    logger.debug("RingPlacer.placeRingSubstituents() start");
    IRing ring = null;
    IAtom atom = null;
    IRingSet rings = null;
    IAtomContainer unplacedPartners = rs.getBuilder().newInstance(IAtomContainer.class);
    IAtomContainer sharedAtoms = rs.getBuilder().newInstance(IAtomContainer.class);
    IAtomContainer primaryAtoms = rs.getBuilder().newInstance(IAtomContainer.class);
    IAtomContainer treatedAtoms = rs.getBuilder().newInstance(IAtomContainer.class);
    Point2d centerOfRingGravity = null;
    for (int j = 0; j < rs.getAtomContainerCount(); j++) {
      ring = (IRing) rs.getAtomContainer(j); /* Get the j-th Ring in RingSet rs */
      for (int k = 0; k < ring.getAtomCount(); k++) {
        unplacedPartners.removeAllElements();
        sharedAtoms.removeAllElements();
        primaryAtoms.removeAllElements();
        atom = ring.getAtom(k);
        rings = rs.getRings(atom);
        centerOfRingGravity = GeometryTools.get2DCenter(rings);
        atomPlacer.partitionPartners(atom, unplacedPartners, sharedAtoms);
        atomPlacer.markNotPlaced(unplacedPartners);
        try {
          for (int f = 0; f < unplacedPartners.getAtomCount(); f++) {
            logger.debug(
                "placeRingSubstituents->unplacedPartners: "
                    + (molecule.getAtomNumber(unplacedPartners.getAtom(f)) + 1));
          }
        } catch (Exception exc) {
        }

        treatedAtoms.add(unplacedPartners);
        if (unplacedPartners.getAtomCount() > 0) {
          atomPlacer.distributePartners(
              atom, sharedAtoms, centerOfRingGravity, unplacedPartners, bondLength);
        }
      }
    }
    logger.debug("RingPlacer.placeRingSubstituents() end");
    return treatedAtoms;
  }
Beispiel #26
0
 /**
  * Returns the bridge atoms, that is the outermost atoms in the chain of more than two atoms which
  * are shared by two rings
  *
  * @param sharedAtoms The atoms (n > 2) which are shared by two rings
  * @return The bridge atoms, i.e. the outermost atoms in the chain of more than two atoms which
  *     are shared by two rings
  */
 private IAtom[] getBridgeAtoms(IAtomContainer sharedAtoms) {
   IAtom[] bridgeAtoms = new IAtom[2];
   IAtom atom;
   int counter = 0;
   for (int f = 0; f < sharedAtoms.getAtomCount(); f++) {
     atom = sharedAtoms.getAtom(f);
     if (sharedAtoms.getConnectedAtomsList(atom).size() == 1) {
       bridgeAtoms[counter] = atom;
       counter++;
     }
   }
   return bridgeAtoms;
 }
  /**
   * compatibilityGraphCEdgeZero is used to build up of the edges of the compatibility graph BIS
   *
   * @return
   * @throws IOException
   */
  private int compatibilityGraphCEdgeZero() throws IOException {

    int compGraphNodesCZeroListSize = compGraphNodesCZero.size();

    for (int a = 0; a < compGraphNodesCZeroListSize; a += 4) {
      int index_a = compGraphNodesCZero.get(a);
      int index_aPlus1 = compGraphNodesCZero.get(a + 1);
      for (int b = a + 4; b < compGraphNodesCZeroListSize; b += 4) {
        int index_b = compGraphNodesCZero.get(b);
        int index_bPlus1 = compGraphNodesCZero.get(b + 1);

        // if element atomCont !=jIndex and atoms on the adjacent sides of the bonds are not equal
        if ((a != b) && (index_a != index_b) && (index_aPlus1 != index_bPlus1)) {

          IBond reactantBond;
          IBond productBond;

          reactantBond = source.getBond(source.getAtom(index_a), source.getAtom(index_b));
          productBond = target.getBond(target.getAtom(index_aPlus1), target.getAtom(index_bPlus1));

          if (reactantBond != null && productBond != null) {
            addZeroEdges(reactantBond, productBond, a, b);
          } else if (reactantBond == null
              && productBond == null
              && source.getAtomCount() < 50
              && target.getAtomCount() < 50) {
            // 50 unique condition to speed up the AAM
            dEdges.add((a / 4) + 1);
            dEdges.add((b / 4) + 1);
          }
        }
      }
    }

    // Size of C and D edges of the compatibility graph
    cEdgesSize = cEdges.size();
    dEdgesSize = dEdges.size();
    return 0;
  }
  private Map<IAtom, List<String>> labelAtomsBySymbol(IAtomContainer atomCont) {
    Map<IAtom, List<String>> label_list = new HashMap<>();

    for (int i = 0; i < atomCont.getAtomCount(); i++) {
      List<String> label = new ArrayList<>(7);
      for (int a = 0; a < 7; a++) {
        label.add(a, "Z9");
      }

      IAtom refAtom = atomCont.getAtom(i);
      /*
       * Important Step: Discriminate between source atom types
       */
      String referenceAtom;
      if (refAtom instanceof IQueryAtom) {
        referenceAtom =
            ((IQueryAtom) refAtom).getSymbol() == null ? "*" : ((IQueryAtom) refAtom).getSymbol();
        //                System.out.println("referenceAtom " + referenceAtom);
      } else if (!(refAtom instanceof IQueryAtom) && this.matchAtomType) {
        referenceAtom =
            refAtom.getAtomTypeName() == null ? refAtom.getSymbol() : refAtom.getAtomTypeName();
      } else {
        referenceAtom = refAtom.getSymbol();
      }
      label.set(0, referenceAtom);
      List<IAtom> connAtoms = atomCont.getConnectedAtomsList(refAtom);

      int counter = 1;

      for (IAtom negAtom : connAtoms) {
        String neighbouringAtom;
        if (refAtom instanceof IQueryAtom) {
          neighbouringAtom =
              ((IQueryAtom) negAtom).getSymbol() == null ? "*" : ((IQueryAtom) negAtom).getSymbol();
          //                    System.out.println("neighbouringAtom " + neighbouringAtom);
        } else if (!(negAtom instanceof IQueryAtom) && this.matchAtomType) {
          neighbouringAtom =
              negAtom.getAtomTypeName() == null ? negAtom.getSymbol() : negAtom.getAtomTypeName();
        } else {
          neighbouringAtom = negAtom.getSymbol();
        }
        label.set(counter, neighbouringAtom);
        counter += 1;
      }
      //            System.out.println("label " + label);
      bubbleSort(label);
      label_list.put(refAtom, label);
    }
    return label_list;
  }
Beispiel #29
0
 /**
  * Removes all atoms and electronContainers of a given atomcontainer from this container.
  *
  * @param atomContainer The atomcontainer to be removed
  */
 public void remove(IAtomContainer atomContainer) {
   for (int f = 0; f < atomContainer.getAtomCount(); f++) {
     removeAtom(atomContainer.getAtom(f));
   }
   for (int f = 0; f < atomContainer.getBondCount(); f++) {
     removeBond(atomContainer.getBond(f));
   }
   for (int f = 0; f < atomContainer.getLonePairCount(); f++) {
     removeLonePair(atomContainer.getLonePair(f));
   }
   for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) {
     removeSingleElectron(atomContainer.getSingleElectron(f));
   }
 }
Beispiel #30
0
 /**
  * Generated coordinates for a given ring. Multiplexes to special handlers for the different
  * possible situations (spiro-, fusion-, bridged attachement)
  *
  * @param ring The ring to be placed
  * @param sharedAtoms The atoms of this ring, also members of another ring, which are already
  *     placed
  * @param sharedAtomsCenter The geometric center of these atoms
  * @param ringCenterVector A vector pointing the the center of the new ring
  * @param bondLength The standard bondlength
  */
 public void placeRing(
     IRing ring,
     IAtomContainer sharedAtoms,
     Point2d sharedAtomsCenter,
     Vector2d ringCenterVector,
     double bondLength) {
   int sharedAtomCount = sharedAtoms.getAtomCount();
   logger.debug("placeRing -> sharedAtomCount: " + sharedAtomCount);
   if (sharedAtomCount > 2) {
     placeBridgedRing(ring, sharedAtoms, sharedAtomsCenter, ringCenterVector, bondLength);
   } else if (sharedAtomCount == 2) {
     placeFusedRing(ring, sharedAtoms, sharedAtomsCenter, ringCenterVector, bondLength);
   } else if (sharedAtomCount == 1) {
     placeSpiroRing(ring, sharedAtoms, sharedAtomsCenter, ringCenterVector, bondLength);
   }
 }