示例#1
0
  /**
   * Test reading from a XML config file with content like:
   *
   * <pre>
   *   <atomType id="C">
   *    <!-- for example in CC-->
   *    <atom elementType="C" formalCharge="0">
   *      <scalar dataType="xsd:double" dictRef="cdk:maxBondOrder">1.0</scalar>
   *      <scalar dataType="xsd:double" dictRef="cdk:bondOrderSum">4.0</scalar>
   *      <scalar dataType="xsd:integer" dictRef="cdk:formalNeighbourCount">4</scalar>
   *      <scalar dataType="xsd:integer" dictRef="cdk:valency">4</scalar>
   *    </atom>
   *    <scalar dataType="xsd:string" dictRef="cdk:hybridization">sp3</scalar>
   *    <scalar dataType="xsd:string" dictRef="cdk:DA">-</scalar>
   *    <scalar dataType="xsd:string" dictRef="cdk:sphericalMatcher">[CSP]-[0-4][-]?+;[A-Za-z\+\-&amp;&amp;[^=%]]{0,6}[(].*+</scalar>
   *  </atomType>
   * </pre>
   *
   * @throws Exception if the atom typ info cannot be loaded
   */
  @Test
  public void testGetAtomTypeFromMM2() throws Exception {
    AtomTypeFactory factory;
    factory =
        AtomTypeFactory.getInstance(
            "org/openscience/cdk/config/data/mm2_atomtypes.xml", new ChemObject().getBuilder());

    IAtomType atomType = factory.getAtomType("C");
    Assert.assertNotNull(atomType);
    Assert.assertEquals("C", atomType.getSymbol());
    Assert.assertEquals("C", atomType.getAtomTypeName());
    Assert.assertEquals(
        "[CSP]-[0-4][-]?+;[A-Za-z\\+\\-&&[^=%]]{0,6}[(].*+",
        atomType.getProperty(CDKConstants.SPHERICAL_MATCHER));
    Assert.assertEquals(Hybridization.SP3, atomType.getHybridization());

    atomType = factory.getAtomType("Sthi");
    Assert.assertNotNull(atomType);
    Assert.assertEquals("S", atomType.getSymbol());
    Assert.assertEquals("Sthi", atomType.getAtomTypeName());
    Assert.assertEquals(
        "S-[2];[H]{0,3}+=C.*+", atomType.getProperty(CDKConstants.SPHERICAL_MATCHER));
    Assert.assertEquals(Hybridization.SP2, atomType.getHybridization());
    Assert.assertTrue(atomType.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR));
    Assert.assertEquals(5, atomType.getProperty(CDKConstants.PART_OF_RING_OF_SIZE));
  }
 /** Tests if the electron count matches the H&uuml;ckel 4n+2 rule. */
 private static boolean isHueckelValid(IAtomContainer singleRing) throws CDKException {
   int electronCount = 0;
   for (IAtom ringAtom : singleRing.atoms()) {
     if (ringAtom.getHybridization() != CDKConstants.UNSET
             && (ringAtom.getHybridization() == Hybridization.SP2)
         || ringAtom.getHybridization() == Hybridization.PLANAR3) {
       // for example, a carbon
       // note: the double bond is in the ring, that has been tested earlier
       // FIXME: this does assume bond orders to be resolved too, when detecting
       // sprouting double bonds
       if ("N.planar3".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("N.minus.planar3".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("N.amide".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("S.2".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("S.planar3".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("C.minus.planar".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("O.planar3".equals(ringAtom.getAtomTypeName())) {
         electronCount += 2;
       } else if ("N.sp2.3".equals(ringAtom.getAtomTypeName())) {
         electronCount += 1;
       } else {
         if (factory == null) {
           factory =
               AtomTypeFactory.getInstance(
                   "org/openscience/cdk/dict/data/cdk-atom-types.owl", ringAtom.getBuilder());
         }
         IAtomType type = factory.getAtomType(ringAtom.getAtomTypeName());
         Object property = type.getProperty(CDKConstants.PI_BOND_COUNT);
         if (property != null && property instanceof Integer) {
           electronCount += ((Integer) property).intValue();
         }
       }
     } else if (ringAtom.getHybridization() != null
         && ringAtom.getHybridization() == Hybridization.SP3
         && getLonePairCount(ringAtom) > 0) {
       // for example, a nitrogen or oxygen
       electronCount += 2;
     }
   }
   return (electronCount % 4 == 2) && (electronCount > 2);
 }
示例#3
0
  @Test
  public void testGetAtomTypeFromOWL_Sybyl() throws Exception {
    AtomTypeFactory factory =
        AtomTypeFactory.getInstance(
            "org/openscience/cdk/dict/data/sybyl-atom-types.owl", new ChemObject().getBuilder());
    IAtomType atomType = factory.getAtomType("C.3");

    Assert.assertNotNull(atomType);
    Assert.assertEquals("C", atomType.getSymbol());
    Assert.assertEquals("C.3", atomType.getAtomTypeName());
    Assert.assertEquals(4, atomType.getFormalNeighbourCount().intValue());
    Assert.assertEquals(IAtomType.Hybridization.SP3, atomType.getHybridization());
    Assert.assertEquals(0, atomType.getFormalCharge().intValue());
    Assert.assertNotNull(atomType.getProperty(CDKConstants.LONE_PAIR_COUNT));
    Assert.assertTrue(atomType.getProperty(CDKConstants.LONE_PAIR_COUNT) instanceof Integer);
    Assert.assertEquals(
        0, ((Integer) atomType.getProperty(CDKConstants.LONE_PAIR_COUNT)).intValue());
    Assert.assertNotNull(atomType.getProperty(CDKConstants.PI_BOND_COUNT));
    Assert.assertTrue(atomType.getProperty(CDKConstants.PI_BOND_COUNT) instanceof Integer);
    Assert.assertEquals(0, ((Integer) atomType.getProperty(CDKConstants.PI_BOND_COUNT)).intValue());
  }