public String perceiveCDKAtomTypes(IMolecule mol)
             throws InvocationTargetException {
     
     ICDKMolecule cdkmol;
     
     try {
         cdkmol = cdk.asCDKMolecule(mol);
     } 
     catch ( BioclipseException e ) {
         e.printStackTrace();
         throw new InvocationTargetException(
                       e, "Error while creating a ICDKMolecule" );
     }
     
     IAtomContainer ac = cdkmol.getAtomContainer();
     CDKAtomTypeMatcher cdkMatcher 
         = CDKAtomTypeMatcher.getInstance(ac.getBuilder());
     
     StringBuffer result = new StringBuffer();
     int i = 1;
     for (IAtom atom : ac.atoms()) {
         IAtomType type = null;
         try {
             type = cdkMatcher.findMatchingAtomType(ac, atom);
         } 
         catch ( CDKException e ) {}
         result.append(i).append(':').append(
             type != null ? type.getAtomTypeName() : "null"
         ).append('\n'); // FIXME: should use NEWLINE here
         i++;
     }
     return result.toString();
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 @Test
 public void testGetAtomType_String() throws Exception {
   IAtomType atomType = atf.getAtomType("C4");
   Assert.assertNotNull(atomType);
   Assert.assertEquals("C", atomType.getSymbol());
   Assert.assertEquals("C4", atomType.getAtomTypeName());
   Assert.assertEquals(4.0, atomType.getBondOrderSum(), 0.001);
   Assert.assertEquals(IBond.Order.TRIPLE, atomType.getMaxBondOrder());
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
0
  @Test
  public void testGetAtomTypeFromJmol() throws Exception {
    AtomTypeFactory factory =
        AtomTypeFactory.getInstance(
            "org/openscience/cdk/config/data/jmol_atomtypes.txt", new ChemObject().getBuilder());
    IAtomType atomType = factory.getAtomType("H");

    Assert.assertNotNull(atomType);
    Assert.assertEquals("H", atomType.getSymbol());
    Assert.assertEquals("H", atomType.getAtomTypeName());
  }
	/**
	 * Clean up chemical model ,removing duplicates empty molecules etc
	 * 
	 * @param chemModel
	 * @param avoidOverlap
	 * @throws CDKException
	 */
	public static void cleanUpChemModel(final IChemModel chemModel,
			final boolean avoidOverlap, final AbstractJChemPaintPanel panel)
			throws CDKException {
		JChemPaint.setReactionIDs(chemModel);
		JChemPaint.replaceReferencesWithClones(chemModel);

		// check the model is not completely empty
		if (ChemModelManipulator.getBondCount(chemModel) == 0
				&& ChemModelManipulator.getAtomCount(chemModel) == 0) {
			throw new CDKException(
					"Structure does not have bonds or atoms. Cannot depict structure.");
		}
		JChemPaint.removeDuplicateAtomContainers(chemModel);
		JChemPaint.checkCoordinates(chemModel);
		JChemPaint.removeEmptyAtomContainers(chemModel);

		if (avoidOverlap) {
			try {
				ControllerHub.avoidOverlap(chemModel);
			} catch (final Exception e) {
				JOptionPane.showMessageDialog(panel,
						GT._("Structure could not be generated"));
				throw new CDKException("Cannot depict structure");
			}
		}

		// We update implicit Hs in any case
		final CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher
				.getInstance(chemModel.getBuilder());
		for (final IAtomContainer container : ChemModelManipulator
				.getAllAtomContainers(chemModel)) {
			for (final IAtom atom : container.atoms()) {
				if (!(atom instanceof IPseudoAtom)) {
					try {
						final IAtomType type = matcher.findMatchingAtomType(
								container, atom);
						if (type != null
								&& type.getFormalNeighbourCount() != null) {
							final int connectedAtomCount = container
									.getConnectedAtomsCount(atom);
							atom.setImplicitHydrogenCount(type
									.getFormalNeighbourCount()
									- connectedAtomCount);
						}
					} catch (final CDKException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
Exemplo n.º 7
0
 /** Tests if the electron count matches the Hü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);
 }
  /**
   * 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());
  }
    public String perceiveSybylAtomTypes(IMolecule mol)
                        throws InvocationTargetException {
        
        ICDKMolecule cdkmol;
        
        try {
            cdkmol = cdk.asCDKMolecule(mol);
        } 
        catch (BioclipseException e) {
            System.out.println("Error converting cdk10 to cdk");
            e.printStackTrace();
            throw new InvocationTargetException(e);
        }
        
        IAtomContainer ac = cdkmol.getAtomContainer();
        CDKAtomTypeMatcher cdkMatcher 
            = CDKAtomTypeMatcher.getInstance(ac.getBuilder());
        AtomTypeMapper mapper 
            = AtomTypeMapper.getInstance(
                 "org/openscience/cdk/dict/data/cdk-sybyl-mappings.owl" );

        IAtomType[] sybylTypes = new IAtomType[ac.getAtomCount()];
        
        int atomCounter = 0;
        int a=0;
        for (IAtom atom : ac.atoms()) {
            IAtomType type;
            try {
                type = cdkMatcher.findMatchingAtomType(ac, atom);
            } 
            catch (CDKException e) {
                type = null;
            }
            if (type==null) {
//                logger.debug("AT null for atom: " + atom);
                type = atom.getBuilder().newAtomType(atom.getSymbol());
                type.setAtomTypeName("X");
            }
            AtomTypeManipulator.configure(atom, type);
            a++;
        }
        try {
            CDKHueckelAromaticityDetector.detectAromaticity(ac);
//            System.out.println("Arom: " 
//                + CDKHueckelAromaticityDetector.detectAromaticity(ac) );
		    } 
        catch (CDKException e) {
			    logger.debug("Failed to perceive aromaticity: " + e.getMessage());
		    }
        for (IAtom atom : ac.atoms()) {
            String mappedType = mapper.mapAtomType(atom.getAtomTypeName());
            if ("C.2".equals(mappedType)
                    && atom.getFlag(CDKConstants.ISAROMATIC)) {
                mappedType = "C.ar";
            } 
            else if ("N.pl3".equals(mappedType)
                    && atom.getFlag(CDKConstants.ISAROMATIC)) {
                mappedType = "N.ar";
            }
            try {
                sybylTypes[atomCounter] = factory.getAtomType(mappedType);
		        } 
            catch (NoSuchAtomTypeException e) {
                // yes, setting null's here is important
                sybylTypes[atomCounter] = null; 
			      }
            atomCounter++;
        }
        StringBuffer result = new StringBuffer();
        // now that full perception is finished, we can set atom type names:
        for (int i = 0; i < sybylTypes.length; i++) {
            if (sybylTypes[i] != null) {
                ac.getAtom(i).setAtomTypeName(sybylTypes[i].getAtomTypeName());
            } 
            else {
                ac.getAtom(i).setAtomTypeName("X");
            }
            
            result.append(i).append(':').append(ac.getAtom(i).getAtomTypeName())
                  /*.append("\n")*/;

        }
        return result.toString();
    }
Exemplo n.º 10
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));
  }
Exemplo n.º 11
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());
  }