/**
   * 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;
  }
示例#2
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();
  }
示例#3
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;
  }
示例#4
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);
  }
示例#5
0
  /**
   * (2S)-butan-2-ol
   *
   * @cdk.inchi InChI=1/C4H10O/c1-3-4(2)5/h4-5H,3H2,1-2H3/t4-/s2
   */
  @Test
  public void _2S_butan_2_ol() throws Exception {

    IAtomContainer ac = new AtomContainer();
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("O"));
    ac.addAtom(new Atom("H"));
    ac.addBond(0, 1, SINGLE);
    ac.addBond(1, 2, SINGLE);
    ac.addBond(2, 3, SINGLE);
    ac.addBond(2, 4, SINGLE);
    ac.addBond(2, 5, SINGLE);

    ac.addStereoElement(
        new TetrahedralChirality(
            ac.getAtom(2),
            new IAtom[] {
              ac.getAtom(1), // C-C
              ac.getAtom(3), // C
              ac.getAtom(4), // O
              ac.getAtom(5), // H
            },
            ANTI_CLOCKWISE));

    Graph g = convert(ac);
    assertThat(g.toSmiles(), is("CC[C@](C)(O)[H]"));
  }
示例#6
0
 @Test
 public void testGetChiralAtom() {
   TetrahedralChirality chirality =
       new TetrahedralChirality(molecule.getAtom(1), ligands, Stereo.CLOCKWISE);
   Assert.assertNotNull(chirality);
   Assert.assertEquals(molecule.getAtom(1), chirality.getChiralAtom());
 }
示例#7
0
  /**
   * @param list
   * @param source
   * @param target
   */
  protected synchronized void identifySingleAtomsMatchedParts(
      List<CDKRMap> list, IAtomContainer source, IAtomContainer target) {

    //        List<IAtom> array1 = new ArrayList<>();
    //        List<IAtom> array2 = new ArrayList<>();

    /* We have serial numbers of the bonds/Atoms to delete
     * Now we will collect the actual bond/Atoms rather than
     * serial number for deletion. RonP flag check whether reactant is
     * mapped on product or Vise Versa
     */
    TreeMap<Integer, Integer> atomNumbersFromContainer = new TreeMap<>();

    for (CDKRMap rmap : list) {
      // System.err.print("Map " + o.getClass());

      IAtom sAtom = source.getAtom(rmap.getId1());
      IAtom tAtom = target.getAtom(rmap.getId2());

      //            array1.add(sAtom);
      //            array2.add(tAtom);
      int indexI = source.getAtomNumber(sAtom);
      int indexJ = target.getAtomNumber(tAtom);

      atomNumbersFromContainer.put(indexI, indexJ);

      /*Added the Mapping Numbers to the FinalMapping*
       */
      getMappings().add(atomNumbersFromContainer);
    }
  }
示例#8
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);
    }
  }
示例#9
0
文件: CIPTool.java 项目: jaypat87/cdk
 /**
  * Creates a ligand attached to a single chiral atom, where the involved atoms are identified by
  * there index in the {@link IAtomContainer}. For ligand atom, {@link #HYDROGEN} can be passed as
  * index, which will indicate the presence of an implicit hydrogen, not explicitly present in the
  * chemical graph of the given <code>container</code>.
  *
  * @param container {@link IAtomContainer} for which the returned {@link ILigand}s are defined
  * @param visitedAtoms a list of atoms already visited in the analysis
  * @param chiralAtom an integer pointing to the {@link IAtom} index of the chiral atom
  * @param ligandAtom an integer pointing to the {@link IAtom} index of the {@link ILigand}
  * @return the created {@link ILigand}
  */
 public static ILigand defineLigand(
     IAtomContainer container, VisitedAtoms visitedAtoms, int chiralAtom, int ligandAtom) {
   if (ligandAtom == HYDROGEN) {
     return new ImplicitHydrogenLigand(container, visitedAtoms, container.getAtom(chiralAtom));
   } else {
     return new Ligand(
         container, visitedAtoms, container.getAtom(chiralAtom), container.getAtom(ligandAtom));
   }
 }
示例#10
0
  @Test
  public void s_penta_2_3_diene_expl_h() throws Exception {
    IAtomContainer m = new AtomContainer(5, 4, 0, 0);
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("H"));
    m.addAtom(new Atom("H"));
    m.addBond(0, 1, IBond.Order.SINGLE);
    m.addBond(1, 2, IBond.Order.DOUBLE);
    m.addBond(2, 3, IBond.Order.DOUBLE);
    m.addBond(3, 4, IBond.Order.SINGLE);
    m.addBond(1, 5, IBond.Order.SINGLE);
    m.addBond(3, 6, IBond.Order.SINGLE);

    int[][] atoms =
        new int[][] {
          {0, 5, 6, 4},
          {5, 0, 6, 4},
          {5, 0, 4, 6},
          {0, 5, 4, 6},
          {4, 6, 5, 0},
          {4, 6, 0, 5},
          {6, 4, 0, 5},
          {6, 4, 5, 0},
        };
    Stereo[] stereos =
        new Stereo[] {
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE,
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE,
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE,
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE
        };

    for (int i = 0; i < atoms.length; i++) {

      IStereoElement element =
          new ExtendedTetrahedral(
              m.getAtom(2),
              new IAtom[] {
                m.getAtom(atoms[i][0]),
                m.getAtom(atoms[i][1]),
                m.getAtom(atoms[i][2]),
                m.getAtom(atoms[i][3])
              },
              stereos[i]);
      m.setStereoElements(Collections.singletonList(element));

      assertThat(convert(m).toSmiles(), is("CC(=[C@]=C(C)[H])[H]"));
    }
  }
示例#11
0
 @Test
 public void testGetStereo() {
   TetrahedralChirality chirality =
       new TetrahedralChirality(molecule.getAtom(1), ligands, Stereo.CLOCKWISE);
   Assert.assertNotNull(chirality);
   Assert.assertEquals(molecule.getAtom(1), chirality.getChiralAtom());
   for (int i = 0; i < ligands.length; i++) {
     Assert.assertEquals(ligands[i], chirality.getLigands()[i]);
   }
   Assert.assertEquals(TetrahedralChirality.Stereo.CLOCKWISE, chirality.getStereo());
 }
示例#12
0
 @Test
 public void writeAtomClass() throws Exception {
   IAtomContainer ac = new AtomContainer();
   ac.addAtom(new Atom("C"));
   ac.addAtom(new Atom("C"));
   ac.addAtom(new Atom("O"));
   ac.addBond(0, 1, SINGLE);
   ac.addBond(1, 2, SINGLE);
   ac.getAtom(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING, 3);
   ac.getAtom(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING, 1);
   ac.getAtom(2).setProperty(CDKConstants.ATOM_ATOM_MAPPING, 2);
   assertThat(convert(ac).toSmiles(), is("[CH3:3][CH2:1][OH:2]"));
 }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testCDKConstants_REACTIVE_CENTER() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

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

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

    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.TRUE);
    paramList.add(param);
    type.setParameterList(paramList);

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

    IAtomContainer reactant = setOfReactions.getReaction(0).getReactants().getAtomContainer(0);
    Assert.assertTrue(molecule.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
  }
 private void processBondsBlock(int lineCount, IAtomContainer container) throws IOException {
   for (int i = 0; i < lineCount; i++) {
     String line = input.readLine();
     int atom1 = Integer.parseInt(line.substring(10, 13).trim()) - 1;
     int atom2 = Integer.parseInt(line.substring(16, 19).trim()) - 1;
     if (container.getBond(container.getAtom(atom1), container.getAtom(atom2)) == null) {
       IBond bond =
           container.getBuilder().newBond(container.getAtom(atom1), container.getAtom(atom2));
       int order = Integer.parseInt(line.substring(23).trim());
       bond.setOrder(BondManipulator.createBondOrder((double) order));
       container.addBond(bond);
     } // else: bond already present; CTX store the bonds twice
   }
 }
示例#15
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());
    }
  }
 /**
  * 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);
     }
   }
 }
示例#17
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());
    }
  }
 /**
  * Obtain the coordinates of atoms in a cycle.
  *
  * @param cycle vertices that form a cycles
  * @param container structure representation
  * @return coordinates of the cycle
  */
 private static Point2d[] coordinatesOfCycle(int[] cycle, IAtomContainer container) {
   Point2d[] points = new Point2d[cycle.length];
   for (int i = 0; i < cycle.length; i++) {
     points[i] = container.getAtom(cycle[i]).getPoint2d();
   }
   return points;
 }
  /**
   * The method returns partial charges assigned to an heavy atom through MMFF94 method. It is
   * needed to call the addExplicitHydrogensToSatisfyValency method from the class
   * tools.HydrogenAdder.
   *
   * @param atom The IAtom for which the DescriptorValue is requested
   * @param org AtomContainer
   * @return partial charge of parameter atom
   */
  @Override
  public DescriptorValue calculate(IAtom atom, IAtomContainer org) {

    if (atom.getProperty(CHARGE_CACHE) == null) {

      IAtomContainer copy;
      try {
        copy = org.clone();
      } catch (CloneNotSupportedException e) {
        return new DescriptorValue(
            getSpecification(),
            getParameterNames(),
            getParameters(),
            new DoubleResult(Double.NaN),
            NAMES);
      }

      for (IAtom a : org.atoms()) {
        if (a.getImplicitHydrogenCount() == null || a.getImplicitHydrogenCount() != 0) {
          logger.error("Hydrogens must be explict for MMFF charge calculation");
          return new DescriptorValue(
              getSpecification(),
              getParameterNames(),
              getParameters(),
              new DoubleResult(Double.NaN),
              NAMES);
        }
      }

      if (!mmff.assignAtomTypes(copy))
        logger.warn("One or more atoms could not be assigned an MMFF atom type");
      mmff.partialCharges(copy);
      mmff.clearProps(copy);

      // cache charges
      for (int i = 0; i < org.getAtomCount(); i++) {
        org.getAtom(i).setProperty(CHARGE_CACHE, copy.getAtom(i).getCharge());
      }
    }

    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        new DoubleResult(atom.getProperty(CHARGE_CACHE, Double.class)),
        NAMES);
  }
  /**
   * Given a projected cycle, assign the exocyclic substituents to being above of below the
   * projection. For Haworth projections, the substituents must be directly up or down (within some
   * threshold).
   *
   * @param cycle vertices that form a cycle
   * @param above vertices that will be above the cycle (filled by method)
   * @param below vertices that will be below the cycle (filled by method)
   * @param projection the type of projection
   * @param horizontalXy offset from the horizontal axis
   * @return assignment okay (true), not okay (false)
   */
  private boolean assignSubstituents(
      int[] cycle, int[] above, int[] below, WoundProjection projection, Point2d horizontalXy) {

    boolean haworth = projection.projection == Projection.Haworth;

    int found = 0;

    for (int i = 1; i <= cycle.length; i++) {

      int j = i % cycle.length;

      int prev = cycle[i - 1];
      int curr = cycle[j];
      int next = cycle[(i + 1) % cycle.length];

      // get the substituents not in the ring (i.e. excl. prev and next)
      int[] ws = filter(graph[curr], prev, next);

      if (ws.length > 2 || ws.length < 1) continue;

      Point2d centerXy = container.getAtom(curr).getPoint2d();

      // determine the direction of each substituent
      for (final int w : ws) {
        Point2d otherXy = container.getAtom(w).getPoint2d();
        Direction direction = direction(centerXy, otherXy, horizontalXy, haworth);

        switch (direction) {
          case Up:
            if (above[j] != curr) return false;
            above[j] = w;
            break;
          case Down:
            if (below[j] != curr) return false;
            below[j] = w;
            break;
          case Other:
            return false;
        }
      }

      if (above[j] != curr || below[j] != curr) found++;
    }

    // must have at least 2 that look projected for Haworth
    return found > 1 || projection.projection != Projection.Haworth;
  }
示例#21
0
 @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());
 }
示例#22
0
 @BeforeClass
 public static void setup() throws Exception {
   molecule = new AtomContainer();
   molecule.addAtom(new Atom("Cl"));
   molecule.addAtom(new Atom("C"));
   molecule.addAtom(new Atom("Br"));
   molecule.addAtom(new Atom("I"));
   molecule.addAtom(new Atom("H"));
   molecule.addBond(0, 1, Order.SINGLE);
   molecule.addBond(1, 2, Order.SINGLE);
   molecule.addBond(1, 3, Order.SINGLE);
   molecule.addBond(1, 4, Order.SINGLE);
   ligands =
       new IAtom[] {
         molecule.getAtom(4), molecule.getAtom(3), molecule.getAtom(2), molecule.getAtom(0)
       };
 }
示例#23
0
 @Test
 public void testToString() {
   TetrahedralChirality chirality =
       new TetrahedralChirality(molecule.getAtom(1), ligands, Stereo.CLOCKWISE);
   String stringRepr = chirality.toString();
   Assert.assertNotSame(0, stringRepr.length());
   Assert.assertFalse(stringRepr.contains("\n"));
 }
示例#24
0
  /**
   * 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();
    }
  }
示例#25
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;
 }
示例#26
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;
 }
  /**
   * 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);
  }
  /**
   * Returns the number of double bond equivalents in this molecule.
   *
   * @param formula The IMolecularFormula to calculate
   * @return The number of DBEs
   * @throws CDKException if DBE cannot be be evaluated
   * @cdk.keyword DBE
   * @cdk.keyword double bond equivalent
   */
  public static double getDBE(IMolecularFormula formula) throws CDKException {
    int valencies[] = new int[5];
    IAtomContainer ac = getAtomContainer(formula);
    AtomTypeFactory factory =
        AtomTypeFactory.getInstance(
            "org/openscience/cdk/config/data/structgen_atomtypes.xml", ac.getBuilder());

    for (int f = 0; f < ac.getAtomCount(); f++) {
      IAtomType[] types = factory.getAtomTypes(ac.getAtom(f).getSymbol());
      if (types.length == 0)
        throw new CDKException(
            "Calculation of double bond equivalents not possible due to problems with element "
                + ac.getAtom(f).getSymbol());
      //			valencies[(int) (types[0].getBondOrderSum() + ac.getAtom(f).getFormalCharge())]++;
      valencies[types[0].getBondOrderSum().intValue()]++;
    }
    return 1 + (valencies[4]) + (valencies[3] / 2) - (valencies[1] / 2);
  }
  @Test
  public void testNotCharged() throws Exception {

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

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

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

    Assert.assertEquals(0.0, result.doubleValue(), 0.00001);
  }
	/**
	 * Helper method to generate 2d coordinates when JChempaint loads a molecule
	 * without 2D coordinates. Typically happens for SMILES strings.
	 * 
	 * @param molecules
	 * @throws Exception
	 */
	private static void generate2dCoordinates(
			final List<IAtomContainer> molecules) {
		final StructureDiagramGenerator sdg = new StructureDiagramGenerator();
		for (int atIdx = 0; atIdx < molecules.size(); atIdx++) {
			final IAtomContainer mol = molecules.get(atIdx);
			sdg.setMolecule(mol.getBuilder().newInstance(IAtomContainer.class,
					mol));
			try {
				sdg.generateCoordinates();
			} catch (final Exception e) {
				e.printStackTrace();
			}
			final IAtomContainer ac = sdg.getMolecule();
			for (int i = 0; i < ac.getAtomCount(); i++) {
				mol.getAtom(i).setPoint2d(ac.getAtom(i).getPoint2d());
			}
		}
	}