/** * The number of contributed electrons for the atom type of the specified * atom type. * * @param atom an atom to get the contribution of * @return the number of electrons */ private static int electronsForAtomType(IAtom atom) { Integer electrons = TYPES.get(atom.getAtomTypeName()); if (electrons != null) return electrons; try { IAtomType atomType = AtomTypeFactory.getInstance("org/openscience/cdk/dict/data/cdk-atom-types.owl", atom.getBuilder()).getAtomType(atom.getAtomTypeName()); electrons = atomType.getProperty(CDKConstants.PI_BOND_COUNT); return electrons != null ? electrons : 0; } catch (NoSuchAtomTypeException e) { throw new IllegalArgumentException(e); } }
/** * Method which assigns van der Waals radii to the biopolymer * default org/openscience/cdk/config/data/pdb_atomtypes.xml * stored in the variable String vanDerWaalsFile. */ public void assignVdWRadiiToProtein() { AtomTypeFactory atf = null; IAtom[] atoms = AtomContainerManipulator.getAtomArray(protein); try { atf = AtomTypeFactory.getInstance(vanDerWaalsFile, atoms[0].getBuilder()); } catch (Exception ex1) { System.out.println("Problem with AtomTypeFactory due to:" + ex1.toString()); } for (int i = 0; i < atoms.length; i++) { try { atf.configure(atoms[i]); } catch (Exception ex2) { logger.error("Problem with atf.configure due to:" + ex2.toString()); } } }
/** * 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); }
/** * Method to create a default AtomTypeFactory, using the structgen atom type list. * * @see #getInstance(String, IChemObjectBuilder) * @param builder IChemObjectBuilder used to make IChemObject instances * @return The AtomTypeFactory for the given data file */ public static AtomTypeFactory getInstance(IChemObjectBuilder builder) { return getInstance("org/openscience/cdk/config/data/structgen_atomtypes.xml", builder); }
if (factory == null) { try { factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/mm2_atomtypes.xml", atomContainer.getBuilder()); } catch (Exception ex1) { return factory.getAtomTypes("DU")[0]; logger.debug("Atom maxBond" + maxBondOrder + " ChemicalGroupConstant " + atomChemicalGroupConstant); for (int j = 0; j < atomTypeIds.length; j++) { tmpMaxBondOrder = factory.getAtomType(atomTypeIds[j]).getMaxBondOrder(); logger.debug(j + "ATOM TYPE " + tmpMaxBondOrder + " " + getSphericalMatcher(atomTypeIds[j])); p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[j])); atomTypeFlag = false; logger.debug("ID in factory true:" + ID); return factory.getAtomType(ID); } else { logger.debug("NoSuchAtomTypeException: Atom is unkown with Symbol:" + atom.getSymbol() + " does not MATCH AtomType. HoseCode:" + atomSphericalMatcher); logger.debug("ID in factory false:" + ID); return factory.getAtomType("DU");
/** * Returns the currently maximum formable bond order for this atom. * * @param atom The atom to be checked * @param ac The AtomContainer that provides the context * @return the currently maximum formable bond order for this atom */ public double getCurrentMaxBondOrder(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return 0; double bondOrderSum = ac.getBondOrderSum(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); double max = 0; double current = 0; for (int f = 0; f < atomTypes.length; f++) { current = hcount + bondOrderSum; if (atomTypes[f].getBondOrderSum() - current > max) { max = atomTypes[f].getBondOrderSum() - current; } } return max; }
/** * Test if all elements up to and including Uranium have atom types. * * @throws Exception */ @Test public void testAllElementsRepresented() throws Exception { AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/dict/data/cdk-atom-types.owl", SilentChemObjectBuilder.getInstance()); Assert.assertTrue("Could not read the atom types", factory.getSize() != 0); String errorMessage = "Elements without atom type(s) defined in the XML:"; final int testUptoAtomicNumber = 36; // TODO: 92 ? int elementsMissingTypes = 0; for (int i = 1; i < testUptoAtomicNumber; i++) { String symbol = PeriodicTable.getSymbol(i); IAtomType[] expectedTypes = factory.getAtomTypes(symbol); if (expectedTypes.length == 0) { errorMessage += " " + symbol; elementsMissingTypes++; } } Assert.assertEquals(errorMessage, 0, elementsMissingTypes); }
private IAtomType getAtomType(String identifier) throws CDKException { IAtomType type = factory.getAtomType(identifier); return type; }
@Test public void testGetInstance_InputStream_String_IChemObjectBuilder() throws Exception { String configFile = "org/openscience/cdk/config/data/structgen_atomtypes.xml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(configFile); AtomTypeFactory atf = AtomTypeFactory.getInstance(ins, "xml", new ChemObject().getBuilder()); Assert.assertNotNull(atf); Assert.assertNotSame(0, atf.getSize()); }
/** * The test seems to be run by JUnit in order in which they found * in the source. Ugly, but @AfterClass does not work because that * methods does cannot assert anything. * * ...not anymore. Bad idea to do have such a test in the first place * but we can hack it by sorting by test name (see fix method order * annotation). */ @Test public void utestCountTestedAtomTypes() { AtomTypeFactory factory = AtomTypeFactory.getInstance( "org/openscience/cdk/config/data/structgen_atomtypes.xml", SilentChemObjectBuilder.getInstance()); IAtomType[] expectedTypes = factory.getAllAtomTypes(); if (expectedTypes.length != testedAtomTypes.size()) { String errorMessage = "Atom types not tested:"; for (IAtomType expectedType : expectedTypes) { if (!testedAtomTypes.containsKey(expectedType.getAtomTypeName())) errorMessage += " " + expectedType.getAtomTypeName(); } Assert.assertEquals(errorMessage, factory.getAllAtomTypes().length, testedAtomTypes.size()); } }
if (atomTypeName == null || atomTypeName.length() == 0) { logger.debug("Using atom symbol because atom type name is empty..."); IAtomType[] types = getAtomTypes(atom.getSymbol()); if (types.length > 0) { logger.warn("Taking first atom type, but other may exist"); atomType = getAtomType(atom.getAtomTypeName());
if (cdkType != null) { try { cdkAtomTypeFactory.configure(oAtom); } catch (CDKException cdke) { logger.warn("Could not configure", resName, " ", atomName);
public void testForDuplicateDefinitions() { IAtomType[] expectedTypesArray = getFactory().getAllAtomTypes(); Set<String> alreadyDefinedTypes = new HashSet<String>(); for (int i = 0; i < expectedTypesArray.length; i++) { String definedType = expectedTypesArray[i].getAtomTypeName(); if (alreadyDefinedTypes.contains(definedType)) { Assert.fail("Duplicate atom type definition in XML: " + definedType); } alreadyDefinedTypes.add(definedType); } }
private boolean createBondsWithRebondTool(IAtomContainer molecule) { RebondTool tool = new RebondTool(2.0, 0.5, 0.5); try { // configure atoms AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/jmol_atomtypes.txt", molecule.getBuilder()); for (IAtom atom : molecule.atoms()) { try { IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); if (types.length > 0) { // just pick the first one AtomTypeManipulator.configure(atom, types[0]); } else { logger.warn("Could not configure atom with symbol: " + atom.getSymbol()); } } catch (Exception e) { logger.warn("Could not configure atom (but don't care): " + e.getMessage()); logger.debug(e); } } tool.rebond(molecule); } catch (Exception e) { logger.error("Could not rebond the polymer: " + e.getMessage()); logger.debug(e); } return true; }
/** * Method to create a default AtomTypeFactory, using the structgen atom type list. * * @see #getInstance(String, IChemObjectBuilder) * @param builder IChemObjectBuilder used to make IChemObject instances * @return The AtomTypeFactory for the given data file */ public static AtomTypeFactory getInstance(IChemObjectBuilder builder) { return getInstance("org/openscience/cdk/config/data/structgen_atomtypes.xml", builder); }
/** * Returns the currently maximum formable bond order for this atom. * * @param atom The atom to be checked * @param ac The AtomContainer that provides the context * @return the currently maximum formable bond order for this atom */ public double getCurrentMaxBondOrder(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return 0; double bondOrderSum = ac.getBondOrderSum(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); double max = 0; double current = 0; for (int f = 0; f < atomTypes.length; f++) { current = hcount + bondOrderSum; if (atomTypes[f].getBondOrderSum() - current > max) { max = atomTypes[f].getBondOrderSum() - current; } } return max; }
private IAtomType getAtomType(String identifier) throws CDKException { IAtomType type = factory.getAtomType(identifier); return type; }
@Test public void testGetSize() throws Exception { AtomTypeFactory atf = AtomTypeFactory.getInstance(new ChemObject().getBuilder()); Assert.assertNotSame(0, atf.getSize()); }
@Test public void testGetAllAtomTypes() throws Exception { AtomTypeFactory atf = AtomTypeFactory.getInstance(new ChemObject().getBuilder()); IAtomType[] types = atf.getAllAtomTypes(); Assert.assertNotNull(types); Assert.assertNotSame(0, types.length); }
if (atomTypeName == null || atomTypeName.length() == 0) { logger.debug("Using atom symbol because atom type name is empty..."); IAtomType[] types = getAtomTypes(atom.getSymbol()); if (types.length > 0) { logger.warn("Taking first atom type, but other may exist"); atomType = getAtomType(atom.getAtomTypeName());