@Test
  public void testSybylAtomTypePerceptionBenzene()
      throws CDKException, FileNotFoundException, IOException, BioclipseException, CoreException,
          InvocationTargetException {

    IAtomContainer ac = MoleculeFactory.makeBenzene();

    ICDKMolecule mol = new CDKMolecule(ac);

    debug.perceiveSybylAtomTypes(mol);

    System.out.println("** BENZENE **");

    System.out.println(AtomContainerDiff.diff(ac, mol.getAtomContainer()));

    for (int i = 0; i < mol.getAtomContainer().getAtomCount(); i++) {
      IAtom a = mol.getAtomContainer().getAtom(i);
      System.out.println("Atom: " + a.getSymbol() + i + ", type=" + a.getAtomTypeName());
    }

    assertEquals("C.ar", mol.getAtomContainer().getAtom(0).getAtomTypeName());
    assertEquals("C.ar", mol.getAtomContainer().getAtom(1).getAtomTypeName());
    assertEquals("C.ar", mol.getAtomContainer().getAtom(2).getAtomTypeName());
    assertEquals("C.ar", mol.getAtomContainer().getAtom(3).getAtomTypeName());
    assertEquals("C.ar", mol.getAtomContainer().getAtom(4).getAtomTypeName());
    assertEquals("C.ar", mol.getAtomContainer().getAtom(5).getAtomTypeName());
  }
Пример #2
0
  /** @cdk.bug 2142400 */
  @Test
  public void testHydrogenCount2() throws Exception {
    String cmlString =
        "<molecule><atomArray>"
            + "<atom id='a1' elementType='C' hydrogenCount='4'/>"
            + "<atom id='a2' elementType='H'/>"
            + "<atom id='a3' elementType='H'/>"
            + "<atom id='a4' elementType='H'/>"
            + "<atom id='a5' elementType='H'/>"
            + "</atomArray>"
            + "<bondArray>"
            + "<bond id='b1' atomRefs2='a1 a2' order='S'/>"
            + "<bond id='b2' atomRefs2='a1 a3' order='S'/>"
            + "<bond id='b3' atomRefs2='a1 a4' order='S'/>"
            + "<bond id='b4' atomRefs2='a1 a5' order='S'/>"
            + "</bondArray></molecule>";

    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(5, mol.getAtomCount());
    IAtom atom = mol.getAtom(0);
    Assert.assertNotNull(atom);
    Assert.assertEquals("C", atom.getSymbol());
    Assert.assertNotNull(atom.getImplicitHydrogenCount());
    Assert.assertEquals(0, atom.getImplicitHydrogenCount().intValue());
  }
Пример #3
0
 // generic method for calculation of distance btw 2 atoms
 private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) {
   double distance;
   Point3d firstPoint = atom1.getPoint3d();
   Point3d secondPoint = atom2.getPoint3d();
   distance = firstPoint.distance(secondPoint);
   return distance;
 }
 protected ArrayList<String> generateHashCodes(Iterable<IAtom> atoms) {
   ArrayList<String> hashes = new ArrayList<String>();
   for (IAtom atom : atoms) {
     hashes.add(Integer.toString(atom.hashCode()));
   }
   return hashes;
 }
Пример #5
0
 @Test
 public void water_Atom() throws Exception {
   IAtom a = new Atom("O");
   a.setImplicitHydrogenCount(2);
   assertThat(new CDKToBeam().toBeamAtom(a).element(), is(Element.Oxygen));
   assertThat(new CDKToBeam().toBeamAtom(a).hydrogens(), is(2));
 }
Пример #6
0
 @Test
 public void methane_Atom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(4);
   assertThat(new CDKToBeam().toBeamAtom(a).element(), is(Element.Carbon));
   assertThat(new CDKToBeam().toBeamAtom(a).hydrogens(), is(4));
 }
Пример #7
0
 public Rectangle2D layoutElectronPairs(
     IAtom atom, IAtomContainer container, int lonePairCount, Graphics2D g) {
   if (lonePairCount == 0) {
     return null;
   }
   Point2d atomPoint = atom.getPoint2d();
   Rectangle2D atomSymbolBounds = this.getTextBounds(g, atom.getSymbol());
   BitSet positions = this.labelManager.getAtomAnnotationPositions(atom);
   double r = this.params.electronRadius;
   double d = r * 2.0;
   for (int i = 0; i < lonePairCount; ++i) {
     LabelManager.AnnotationPosition position = this.labelManager.getNextSparePosition(positions);
     Vector2d v = this.labelManager.getVectorFromPosition(position);
     Vector2d leftPerp = this.labelManager.getLeftPerpendicularFromPosition(position);
     Vector2d rightPerp = this.labelManager.getRightPerpendicularFromPosition(position);
     double dx = (atomSymbolBounds.getWidth() / 2.0 + d) * v.x;
     double dy = (atomSymbolBounds.getHeight() / 2.0 + d) * v.y;
     Point2d lp = new Point2d(atomPoint.x + dx, atomPoint.y + dy);
     Point2d llp = new Point2d(lp);
     llp.scaleAdd(
         (double) (this.params.lonePairSeparation / 2), (Tuple2d) leftPerp, (Tuple2d) llp);
     Point2d rlp = new Point2d(lp);
     rlp.scaleAdd(
         (double) (this.params.lonePairSeparation / 2), (Tuple2d) rightPerp, (Tuple2d) rlp);
     g.fill(new Ellipse2D.Double(llp.x - r, llp.y - r, d, d));
     g.fill(new Ellipse2D.Double(rlp.x - r, rlp.y - r, d, d));
     positions.set(position.ordinal());
   }
   return null;
 }
Пример #8
0
  /**
   * Modules for cleaning a molecule
   *
   * @param molecule
   * @return cleaned AtomContainer
   */
  @TestMethod("testCheckAndCleanMolecule")
  public static IAtomContainer checkAndCleanMolecule(IAtomContainer molecule) {
    boolean isMarkush = false;
    for (IAtom atom : molecule.atoms()) {
      if (atom.getSymbol().equals("R")) {
        isMarkush = true;
        break;
      }
    }

    if (isMarkush) {
      System.err.println("Skipping Markush structure for sanity check");
    }

    // Check for salts and such
    if (!ConnectivityChecker.isConnected(molecule)) {
      // lets see if we have just two parts if so, we assume its a salt and just work
      // on the larger part. Ideally we should have a check to ensure that the smaller
      //  part is a metal/halogen etc.
      IMoleculeSet fragments = ConnectivityChecker.partitionIntoMolecules(molecule);
      if (fragments.getMoleculeCount() > 2) {
        System.err.println("More than 2 components. Skipped");
      } else {
        IMolecule frag1 = fragments.getMolecule(0);
        IMolecule frag2 = fragments.getMolecule(1);
        if (frag1.getAtomCount() > frag2.getAtomCount()) {
          molecule = frag1;
        } else {
          molecule = frag2;
        }
      }
    }
    configure(molecule);
    return molecule;
  }
Пример #9
0
 public boolean matches(IAtom atom) {
   if (atom.getSymbol().equals(this.getSymbol()) && atom.getFlag(CDKConstants.ISAROMATIC)) {
     return true;
   } else {
     return false;
   }
 }
  /**
   * Generate Compatibility Graph Nodes
   *
   * @return
   * @throws IOException
   */
  private int compatibilityGraphNodes() throws IOException {

    compGraphNodes.clear();

    Set<Edge> edges = new HashSet<>();

    int nodeCount = 1;
    Map<IAtom, List<String>> labelAtomsBySymbolA = labelAtomsBySymbol(source);
    Map<IAtom, List<String>> labelAtomsBySymbolB = labelAtomsBySymbol(target);

    for (Map.Entry<IAtom, List<String>> labelA : labelAtomsBySymbolA.entrySet()) {
      //            System.err.println("labelA.getValue() " + labelA.getValue());
      for (Map.Entry<IAtom, List<String>> labelB : labelAtomsBySymbolB.entrySet()) {
        IAtom atom = labelA.getKey();
        if (((atom instanceof IQueryAtom) && ((IQueryAtom) atom).matches(labelB.getKey()))
            || (!(atom instanceof IQueryAtom)
                && atom.getSymbol().equals(labelB.getKey().getSymbol()))) {
          //                        System.err.println("labelB.getValue() " + labelB.getValue());
          int atomNumberI = source.getAtomNumber(labelA.getKey());
          int atomNumberJ = target.getAtomNumber(labelB.getKey());
          Edge e = new Edge(atomNumberI, atomNumberJ);
          if (!edges.contains(e)) {
            edges.add(e);
            compGraphNodes.add(atomNumberI);
            compGraphNodes.add(atomNumberJ);
            compGraphNodes.add(nodeCount);
            nodeCount += 1;
          }
        }
      }
    }
    return 0;
  }
  /**
   * Fill the {@literal coordinates} and {@literal elevation} from the given offset index. If there
   * is only one connection then the second entry (from the offset) will use the coordinates of
   * <i>a</i>. The permutation parity is also built and returned.
   *
   * @param container atom container
   * @param a the central atom
   * @param connected bonds connected to the central atom
   * @param coordinates the coordinates array to fill
   * @param elevations the elevations of the connected atoms
   * @param offset current location in the offset array
   * @return the permutation parity
   */
  private static PermutationParity fill2DCoordinates(
      IAtomContainer container,
      IAtom a,
      List<IBond> connected,
      Point2d[] coordinates,
      int[] elevations,
      int offset) {

    int i = 0;
    coordinates[offset + 1] = a.getPoint2d();
    elevations[offset + 1] = 0;
    int[] indices = new int[2];

    for (IBond bond : connected) {
      if (!isDoubleBond(bond)) {
        IAtom other = bond.getConnectedAtom(a);
        coordinates[i + offset] = other.getPoint2d();
        elevations[i + offset] = elevation(bond, a);
        indices[i] = container.getAtomNumber(other);
        i++;
      }
    }

    if (i == 1) {
      return PermutationParity.IDENTITY;
    } else {
      return new BasicPermutationParity(indices);
    }
  }
Пример #12
0
  /**
   * Place ring with user provided angles.
   *
   * @param ring the ring to place.
   * @param ringCenter center coordinates of the ring.
   * @param bondLength given bond length.
   * @param startAngles a map with start angles when drawing the ring.
   */
  public void placeRing(
      IRing ring, Point2d ringCenter, double bondLength, Map<Integer, Double> startAngles) {
    double radius = this.getNativeRingRadius(ring, bondLength);
    double addAngle = 2 * Math.PI / ring.getRingSize();

    IAtom startAtom = ring.getFirstAtom();
    Point2d p = new Point2d(ringCenter.x + radius, ringCenter.y);
    startAtom.setPoint2d(p);
    double startAngle = Math.PI * 0.5;

    /* Different ring sizes get different start angles to have
     * visually correct placement */
    int ringSize = ring.getRingSize();
    if (startAngles.get(ringSize) != null) startAngle = startAngles.get(ringSize);

    List<IBond> bonds = ring.getConnectedBondsList(startAtom);
    /*
     * Store all atoms to draw in consecutive order relative to the
     * chosen bond.
     */
    Vector<IAtom> atomsToDraw = new Vector<IAtom>();
    IAtom currentAtom = startAtom;
    IBond currentBond = (IBond) bonds.get(0);
    for (int i = 0; i < ring.getBondCount(); i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }
Пример #13
0
 @Test
 public void defaultIsotope() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   a.setMassNumber(12);
   assertThat(new CDKToBeam().toBeamAtom(a).isotope(), is(-1));
 }
Пример #14
0
 @Test
 public void aromaticAtom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   a.setFlag(CDKConstants.ISAROMATIC, true);
   assertTrue(new CDKToBeam().toBeamAtom(a).aromatic());
 }
Пример #15
0
 @Test
 public void testConfigureUnsetProperties() {
   IAtom atom = new NNAtom(Elements.CARBON);
   IAtomType atomType = new NNAtomType(Elements.CARBON);
   atomType.setExactMass(12.0);
   AtomTypeManipulator.configureUnsetProperties(atom, atomType);
   Assert.assertEquals(12.0, atom.getExactMass(), 0.1);
 }
 /**
  * Adds 3D coordinates for singly-bonded ligands of a reference atom (A). Initially designed for
  * hydrogens. The ligands of refAtom are identified and those with 3D coordinates used to generate
  * the new points. (This allows structures with partially known 3D coordinates to be used, as when
  * groups are added.) "Bent" and "non-planar" groups can be formed by taking a subset of the
  * calculated points. Thus R-NH2 could use 2 of the 3 points calculated from (1,iii) nomenclature:
  * A is point to which new ones are "attached". A may have ligands B, C... B may have ligands J,
  * K.. points X1, X2... are returned The cases (see individual routines, which use idealised
  * geometry by default): (0) zero ligands of refAtom. The resultant points are randomly oriented:
  * (i) 1 points required; +x,0,0 (ii) 2 points: use +x,0,0 and -x,0,0 (iii) 3 points: equilateral
  * triangle in xy plane (iv) 4 points x,x,x, x,-x,-x, -x,x,-x, -x,-x,x (1a) 1 ligand(B) of refAtom
  * which itself has a ligand (J) (i) 1 points required; vector along AB vector (ii) 2 points: 2
  * vectors in ABJ plane, staggered and eclipsed wrt J (iii) 3 points: 1 staggered wrt J, the
  * others +- gauche wrt J (1b) 1 ligand(B) of refAtom which has no other ligands. A random J is
  * generated and (1a) applied (2) 2 ligands(B, C) of refAtom A (i) 1 points required; vector in
  * ABC plane bisecting AB, AC. If ABC is linear, no points (ii) 2 points: 2 vectors at angle ang,
  * whose resultant is 2i (3) 3 ligands(B, C, D) of refAtom A (i) 1 points required; if A, B, C, D
  * coplanar, no points. else vector is resultant of BA, CA, DA
  *
  * <p>fails if atom itself has no coordinates or >4 ligands
  *
  * @param atomContainer describing the ligands of refAtom. It could be the whole molecule, or
  *     could be a selected subset of ligands
  * @param refAtom (A) to which new ligands coordinates could be added
  * @param length A-X length
  * @param angle B-A-X angle (used in certain cases)
  * @return Point3D[] points calculated. If request could not be fulfilled (e.g. too many atoms, or
  *     strange geometry, returns empty array (zero length, not null)
  * @cdk.keyword coordinate generation
  */
 public static Point3d[] calculate3DCoordinatesForLigands(
     AtomContainer atomContainer, IAtom refAtom, int nwanted, double length, double angle) {
   Point3d newPoints[] = new Point3d[0];
   Point3d aPoint = refAtom.getPoint3d();
   // get ligands
   List connectedAtoms = atomContainer.getConnectedAtomsList(refAtom);
   if (connectedAtoms == null) {
     return newPoints;
   }
   int nligands = connectedAtoms.size();
   AtomContainer ligandsWithCoords = new AtomContainer();
   for (int i = 0; i < nligands; i++) {
     Atom ligand = (Atom) connectedAtoms.get(i);
     if (ligand.getPoint3d() != null) {
       ligandsWithCoords.addAtom(ligand);
     }
   }
   int nwithCoords = ligandsWithCoords.getAtomCount();
   // too many ligands at present
   if (nwithCoords > 3) {
     return newPoints;
   }
   if (nwithCoords == 0) {
     newPoints = calculate3DCoordinates0(refAtom.getPoint3d(), nwanted, length);
   } else if (nwithCoords == 1) {
     // ligand on A
     IAtom bAtom = ligandsWithCoords.getAtom(0);
     connectedAtoms = ligandsWithCoords.getConnectedAtomsList(bAtom);
     // does B have a ligand (other than A)
     Atom jAtom = null;
     for (int i = 0; i < connectedAtoms.size(); i++) {
       Atom connectedAtom = (Atom) connectedAtoms.get(i);
       if (!connectedAtom.equals(refAtom)) {
         jAtom = connectedAtom;
         break;
       }
     }
     newPoints =
         calculate3DCoordinates1(
             aPoint,
             bAtom.getPoint3d(),
             (jAtom != null) ? jAtom.getPoint3d() : null,
             nwanted,
             length,
             angle);
   } else if (nwithCoords == 2) {
     Point3d bPoint = ligandsWithCoords.getAtom(0).getPoint3d();
     Point3d cPoint = ligandsWithCoords.getAtom(1).getPoint3d();
     newPoints = calculate3DCoordinates2(aPoint, bPoint, cPoint, nwanted, length, angle);
   } else if (nwithCoords == 3) {
     Point3d bPoint = ligandsWithCoords.getAtom(0).getPoint3d();
     Point3d cPoint = ligandsWithCoords.getAtom(1).getPoint3d();
     Point3d dPoint = ligandsWithCoords.getAtom(2).getPoint3d();
     newPoints = new Point3d[1];
     newPoints[0] = calculate3DCoordinates3(aPoint, bPoint, cPoint, dPoint, length);
   }
   return newPoints;
 }
Пример #17
0
 @Test
 public void chargedAtom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   for (int chg = -10; chg < 10; chg++) {
     a.setFormalCharge(chg);
     assertThat(new CDKToBeam().toBeamAtom(a).charge(), is(chg));
   }
 }
Пример #18
0
 public Rectangle2D layoutAtomSymbol(IAtom atom, Graphics2D g) {
   String text = atom.getSymbol();
   if (atom instanceof PseudoAtom) {
     text = ((PseudoAtom) atom).getLabel();
   }
   g.setFont(this.atomSymbolFont);
   Point2d p = atom.getPoint2d();
   return this.layoutText(text, p, g);
 }
Пример #19
0
 private boolean isChemicallyValid(IAtomContainer union) throws CDKException {
   for (IAtom atom : union.atoms()) {
     if ((union.getConnectedBondsCount(atom) + atom.getFormalCharge())
         > atom.getFormalNeighbourCount()) {
       return false;
     }
   }
   return true;
 }
Пример #20
0
 @Test
 public void C13_isomeric() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("C");
   a.setMassNumber(13);
   ac.addAtom(a);
   Graph g = convert(ac);
   assertThat(g.atom(0).isotope(), is(13));
   assertThat(g.toSmiles(), is("[13CH4]"));
 }
Пример #21
0
 @Test
 public void oxidandiide() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("O");
   a.setFormalCharge(-2);
   ac.addAtom(a);
   Graph g = convert(ac);
   assertThat(g.atom(0).charge(), is(-2));
   assertThat(g.toSmiles(), is("[O-2]"));
 }
Пример #22
0
 @Test
 public void C13_nonIsomeric() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("C");
   a.setMassNumber(13);
   ac.addAtom(a);
   Graph g = convert(ac, false, false); // non-isomeric
   assertThat(g.atom(0).isotope(), is(-1));
   assertThat(g.toSmiles(), is("C"));
 }
Пример #23
0
 @Test
 public void azanium() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("N");
   a.setFormalCharge(+1);
   ac.addAtom(a);
   Graph g = convert(ac);
   assertThat(g.atom(0).charge(), is(+1));
   assertThat(g.toSmiles(), is("[NH4+]"));
 }
Пример #24
0
 private boolean checkForGenericAtoms(IAtomContainer mol) {
   for (IAtom atom : mol.atoms()) {
     if (atom instanceof PseudoAtom) return true;
     String className = atom.getClass().getName();
     if (className.equalsIgnoreCase("org.openscience.cdk.PseudoAtom")) {
       return true;
     }
   }
   return false;
 }
 private void processAtomsBlock(int lineCount, IAtomContainer container) throws IOException {
   for (int i = 0; i < lineCount; i++) {
     String line = input.readLine();
     int atomicNumber = Integer.parseInt(line.substring(7, 10).trim());
     IAtom atom = container.getBuilder().newAtom();
     atom.setAtomicNumber(atomicNumber);
     atom.setSymbol(Symbols.byAtomicNumber[atomicNumber]);
     container.addAtom(atom);
   }
 }
Пример #26
0
 @Test
 public void testConfigure_IAtom_IAtomType() {
   IAtom atom = new NNAtom(Elements.CARBON);
   IAtomType atomType = new NNAtomType(Elements.CARBON);
   atomType.setFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR, true);
   AtomTypeManipulator.configure(atom, atomType);
   Assert.assertEquals(
       atomType.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR),
       atom.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR));
 }
Пример #27
0
 private boolean isTerminal(IAtom atom, IAtomContainer atomContainer) {
   int numberOfHeavyAtomsConnected = 0;
   for (IAtom connected : atomContainer.getConnectedAtomsList(atom)) {
     if (connected.getSymbol().equals("H")) {
       continue;
     }
     ++numberOfHeavyAtomsConnected;
   }
   return numberOfHeavyAtomsConnected < 2;
 }
 @Before
 public void setUp() throws Exception {
   // cNH
   IAtom a2 = new Atom("C");
   a2.setImplicitHydrogenCount(0);
   a2.setFlag(CDKConstants.ISAROMATIC, true);
   IAtom a1 = new Atom("N");
   a1.setImplicitHydrogenCount(1);
   this.bond1 = new Bond(a1, a2, Order.DOUBLE);
 }
Пример #29
0
 private boolean getIfBondIsNotRotatable(Molecule mol, IBond bond, IAtomContainer detected) {
   boolean isBondNotRotatable = false;
   int counter = 0;
   IAtom atom0 = bond.getAtom(0);
   IAtom atom1 = bond.getAtom(1);
   if (detected != null) {
     if (detected.contains(bond)) counter += 1;
   }
   if (atom0.getFlag(CDKConstants.ISINRING)) {
     if (atom1.getFlag(CDKConstants.ISINRING)) {
       counter += 1;
     } else {
       if (atom1.getSymbol().equals("H")) counter += 1;
       else counter += 0;
     }
   }
   if (atom0.getSymbol().equals("N") && atom1.getSymbol().equals("C")) {
     if (getIfACarbonIsDoubleBondedToAnOxygen(mol, atom1)) counter += 1;
   }
   if (atom0.getSymbol().equals("C") && atom1.getSymbol().equals("N")) {
     if (getIfACarbonIsDoubleBondedToAnOxygen(mol, atom0)) counter += 1;
   }
   if (counter > 0) isBondNotRotatable = true;
   return isBondNotRotatable;
 }
Пример #30
0
  /**
   * Sets the array of atoms of this AtomContainer.
   *
   * @param atoms The array of atoms to be assigned to this AtomContainer
   * @see #getAtom
   */
  public void setAtoms(IAtom[] atoms) {
    // unregister this as listener with the old atoms
    for (IAtom atom : this.atoms) if (atom != null) atom.removeListener(this);

    this.atoms = atoms;
    for (IAtom atom : atoms) {
      atom.addListener(this);
    }
    this.atomCount = atoms.length;
    notifyChanged();
  }