コード例 #1
0
ファイル: AtomTypeFactoryTest.java プロジェクト: jonalv/cdk
  /**
   * 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));
  }
コード例 #2
0
ファイル: AtomTypeFactoryTest.java プロジェクト: jonalv/cdk
  @Test
  public void testGetAtomTypeFromOWL() throws Exception {
    AtomTypeFactory factory =
        AtomTypeFactory.getInstance(
            "org/openscience/cdk/dict/data/cdk-atom-types.owl", new ChemObject().getBuilder());
    IAtomType atomType = factory.getAtomType("C.sp3");
    Assert.assertNotNull(atomType);
    Assert.assertEquals("C", atomType.getSymbol());
    Assert.assertEquals("C.sp3", atomType.getAtomTypeName());
    Assert.assertEquals(IAtomType.Hybridization.SP3, atomType.getHybridization());
    Assert.assertEquals(0, atomType.getFormalCharge().intValue());
    Assert.assertEquals(4, atomType.getFormalNeighbourCount().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());

    atomType = factory.getAtomType("N.sp2.radical");
    Assert.assertNotNull(atomType);
    Assert.assertEquals("N", atomType.getSymbol());
    Assert.assertEquals("N.sp2.radical", atomType.getAtomTypeName());
    Assert.assertEquals(IAtomType.Hybridization.SP2, atomType.getHybridization());
    Assert.assertEquals(0, atomType.getFormalCharge().intValue());
    Assert.assertEquals(1, atomType.getFormalNeighbourCount().intValue());
    Assert.assertNotNull(atomType.getProperty(CDKConstants.LONE_PAIR_COUNT));
    Assert.assertTrue(atomType.getProperty(CDKConstants.LONE_PAIR_COUNT) instanceof Integer);
    Assert.assertEquals(
        1, ((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(1, ((Integer) atomType.getProperty(CDKConstants.PI_BOND_COUNT)).intValue());

    atomType = factory.getAtomType("N.planar3");
    Assert.assertNotNull(atomType);
    Assert.assertEquals("N", atomType.getSymbol());
    Assert.assertEquals("N.planar3", atomType.getAtomTypeName());
    Assert.assertEquals(IAtomType.Hybridization.PLANAR3, atomType.getHybridization());
    Assert.assertEquals(0, atomType.getFormalCharge().intValue());
    Assert.assertEquals(3, atomType.getFormalNeighbourCount().intValue());
    Assert.assertNotNull(atomType.getProperty(CDKConstants.LONE_PAIR_COUNT));
    Assert.assertTrue(atomType.getProperty(CDKConstants.LONE_PAIR_COUNT) instanceof Integer);
    Assert.assertEquals(
        1, ((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());
  }
コード例 #3
0
  /**
   * This method calculates the hybridization of an atom.
   *
   * @param atom The IAtom for which the DescriptorValue is requested
   * @param container Parameter is the atom container.
   * @return The hybridization
   */
  @TestMethod(value = "testCalculate_IAtomContainer")
  public DescriptorValue calculate(IAtom atom, IAtomContainer container) {
    IAtomType atomType;
    try {
      atomType =
          CDKAtomTypeMatcher.getInstance(atom.getBuilder()).findMatchingAtomType(container, atom);
    } catch (CDKException e) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new IntegerResult((int) Double.NaN), // does that work??
          getDescriptorNames(),
          new CDKException("Atom type was null"));
    }
    if (atomType == null) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new IntegerResult((int) Double.NaN), // does that work??
          getDescriptorNames(),
          new CDKException("Atom type was null"));
    }

    if (atomType.getHybridization() == null) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new IntegerResult((int) Double.NaN), // does that work??
          getDescriptorNames(),
          new CDKException("Hybridization was null"));
    }
    int hybridizationCDK = atomType.getHybridization().ordinal();

    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        new IntegerResult(hybridizationCDK),
        getDescriptorNames());
  }