private IAtomType getAtomType(String identifier) throws CDKException { IAtomType type = factory.getAtomType(identifier); return type; }
private IAtomType getAtomType(String identifier) throws CDKException { IAtomType type = factory.getAtomType(identifier); return type; }
private String getSphericalMatcher(String type) throws CDKException {//NOPMD return getSphericalMatcher(factory.getAtomType(type)); }
private String getSphericalMatcher(String type) throws CDKException {//NOPMD return getSphericalMatcher(factory.getAtomType(type)); }
/** * 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); } }
/** * Checks if an Atom is saturated their lone pair electrons * by comparing it with known AtomTypes. * * @return True, if it's right saturated */ public boolean isSaturated(IAtom atom, IAtomContainer ac) throws CDKException { createAtomTypeFactory(ac.getBuilder()); IAtomType atomType = factory.getAtomType(atom.getAtomTypeName()); int lpCount = (Integer) atomType.getProperty(CDKConstants.LONE_PAIR_COUNT); int foundLPCount = ac.getConnectedLonePairsCount(atom); return foundLPCount >= lpCount; }
private void addTestedAtomType(Map<String, Integer> testedAtomTypes, String expectedID) { if (testedAtomTypes == null) { testedAtomTypes = new HashMap<String, Integer>(); } try { IAtomType type = getFactory().getAtomType(expectedID); Assert.assertNotNull("Attempt to test atom type which is not defined in the " + getAtomTypeListName() + ": " + expectedID, type); } catch (NoSuchAtomTypeException exception) { System.err.println("Attempt to test atom type which is not defined in the " + getAtomTypeListName() + ": " + exception.getMessage()); } if (testedAtomTypes.containsKey(expectedID)) { // increase the count, so that redundancy can be calculated testedAtomTypes.put(expectedID, 1 + testedAtomTypes.get(expectedID)); } else { testedAtomTypes.put(expectedID, 1); } }
@Test public void testToString() throws NoSuchAtomTypeException { AtomTypeFactory factory = AtomTypeFactory.getInstance( "org/openscience/cdk/dict/data/cdk-atom-types.owl", SilentChemObjectBuilder.getInstance() ); IAtomType type = factory.getAtomType("C.sp3"); Assert.assertTrue(type instanceof ImmutableAtomType); String output = type.toString(); Assert.assertTrue(output.contains("ImmutableAtomType(")); Assert.assertTrue(output.contains("MBO:")); }
/** * Saturates an IAtom by adding the appropriate number lone pairs. */ public void saturate(IAtom atom, IAtomContainer ac) throws CDKException { logger.info("Saturating atom by adjusting lone pair electrons..."); IAtomType atomType = factory.getAtomType(atom.getAtomTypeName()); int lpCount = (Integer) atomType.getProperty(CDKConstants.LONE_PAIR_COUNT); int missingLPs = lpCount - ac.getConnectedLonePairsCount(atom); for (int j = 0; j < missingLPs; j++) { ILonePair lp = atom.getBuilder().newInstance(ILonePair.class, atom); ac.addLonePair(lp); } }
@Override public boolean isSaturated(IAtom atom, IAtomContainer container) throws CDKException { IAtomType type = atomTypeList.getAtomType(atom.getAtomTypeName()); if (type == null) throw new CDKException("Atom type is not a recognized CDK atom type: " + atom.getAtomTypeName()); if (type.getFormalNeighbourCount() == CDKConstants.UNSET) throw new CDKException( "Atom type is too general; cannot decide the number of implicit hydrogen to add for: " + atom.getAtomTypeName()); if (type.getProperty(CDKConstants.PI_BOND_COUNT) == CDKConstants.UNSET) throw new CDKException("Atom type is too general; cannot determine the number of pi bonds for: " + atom.getAtomTypeName()); double bondOrderSum = container.getBondOrderSum(atom); IBond.Order maxBondOrder = container.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); int piBondCount = ((Integer) type.getProperty(CDKConstants.PI_BOND_COUNT)).intValue(); int formalNeighborCount = type.getFormalNeighbourCount().intValue(); int typeMaxBondOrder = piBondCount + 1; int typeBondOrderSum = formalNeighborCount + piBondCount; if (bondOrderSum + hcount == typeBondOrderSum && maxBondOrder.numeric() <= typeMaxBondOrder) { return true; } return false; }
@Override public boolean isSaturated(IAtom atom, IAtomContainer container) throws CDKException { IAtomType type = atomTypeList.getAtomType(atom.getAtomTypeName()); if (type == null) throw new CDKException("Atom type is not a recognized CDK atom type: " + atom.getAtomTypeName()); if (type.getFormalNeighbourCount() == CDKConstants.UNSET) throw new CDKException( "Atom type is too general; cannot decide the number of implicit hydrogen to add for: " + atom.getAtomTypeName()); if (type.getProperty(CDKConstants.PI_BOND_COUNT) == CDKConstants.UNSET) throw new CDKException("Atom type is too general; cannot determine the number of pi bonds for: " + atom.getAtomTypeName()); double bondOrderSum = container.getBondOrderSum(atom); IBond.Order maxBondOrder = container.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); int piBondCount = ((Integer) type.getProperty(CDKConstants.PI_BOND_COUNT)).intValue(); int formalNeighborCount = type.getFormalNeighbourCount().intValue(); int typeMaxBondOrder = piBondCount + 1; int typeBondOrderSum = formalNeighborCount + piBondCount; if (bondOrderSum + hcount == typeBondOrderSum && maxBondOrder.numeric() <= typeMaxBondOrder) { return true; } return false; }
double covalentradius = 0; String symbol = atom.getSymbol(); IAtomType type = factory.getAtomType(symbol); covalentradius = type.getCovalentRadius();
/** * Sets the implicit hydrogen count for the indicated IAtom in the given IAtomContainer. * If the atom type is "X", then the atom is assigned zero implicit hydrogens. * * @param container The molecule to which H's will be added * @param atom IAtom to set the implicit hydrogen count for * @throws CDKException Throws if insufficient information is present */ public void addImplicitHydrogens(IAtomContainer container, IAtom atom) throws CDKException { if (atom.getAtomTypeName() == null) throw new CDKException("IAtom is not typed! " + atom.getSymbol()); if ("X".equals(atom.getAtomTypeName())) { if (atom.getImplicitHydrogenCount() == null) atom.setImplicitHydrogenCount(0); return; } IAtomType type = atomTypeList.getAtomType(atom.getAtomTypeName()); if (type == null) throw new CDKException("Atom type is not a recognized CDK atom type: " + atom.getAtomTypeName()); if (type.getFormalNeighbourCount() == CDKConstants.UNSET) throw new CDKException( "Atom type is too general; cannot decide the number of implicit hydrogen to add for: " + atom.getAtomTypeName()); // very simply counting: each missing explicit neighbor is a missing hydrogen atom.setImplicitHydrogenCount(type.getFormalNeighbourCount() - container.getConnectedBondsCount(atom)); } }
/** * Sets the implicit hydrogen count for the indicated IAtom in the given IAtomContainer. * If the atom type is "X", then the atom is assigned zero implicit hydrogens. * * @param container The molecule to which H's will be added * @param atom IAtom to set the implicit hydrogen count for * @throws CDKException Throws if insufficient information is present */ public void addImplicitHydrogens(IAtomContainer container, IAtom atom) throws CDKException { if (atom.getAtomTypeName() == null) throw new CDKException("IAtom is not typed! " + atom.getSymbol()); if ("X".equals(atom.getAtomTypeName())) { if (atom.getImplicitHydrogenCount() == null) atom.setImplicitHydrogenCount(0); return; } IAtomType type = atomTypeList.getAtomType(atom.getAtomTypeName()); if (type == null) throw new CDKException("Atom type is not a recognized CDK atom type: " + atom.getAtomTypeName()); if (type.getFormalNeighbourCount() == CDKConstants.UNSET) throw new CDKException( "Atom type is too general; cannot decide the number of implicit hydrogen to add for: " + atom.getAtomTypeName()); // very simply counting: each missing explicit neighbor is a missing hydrogen atom.setImplicitHydrogenCount(type.getFormalNeighbourCount() - container.getConnectedBondsCount(atom)); } }
/** {@inheritDoc} */ @Override public IAtomType[] findMatchingAtomTypes(IAtomContainer atomContainer) throws CDKException { for (IAtom atom : atomContainer.atoms()) { IAtomType type = cdkMatcher.findMatchingAtomType(atomContainer, atom); atom.setAtomTypeName(type == null ? null : type.getAtomTypeName()); atom.setHybridization(type == null ? null : type.getHybridization()); } Aromaticity.cdkLegacy().apply(atomContainer); IAtomType[] types = new IAtomType[atomContainer.getAtomCount()]; int typeCounter = 0; for (IAtom atom : atomContainer.atoms()) { String mappedType = mapCDKToSybylType(atom); if (mappedType == null) { types[typeCounter] = null; } else { types[typeCounter] = factory.getAtomType(mappedType); } typeCounter++; } return types; }
@Test public void testGetAtomTypeFromPDB() throws Exception { AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/pdb_atomtypes.xml", new ChemObject().getBuilder()); IAtomType atomType = factory.getAtomType("ALA.CA"); Assert.assertNotNull(atomType); Assert.assertEquals("C", atomType.getSymbol()); Assert.assertEquals("ALA.CA", atomType.getAtomTypeName()); }
@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()); }
@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()); }
@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()); }
/** * This method calculates the Covalent radius of an atom. * *@param atom The IAtom for which the DescriptorValue is requested *@param container The {@link IAtomContainer} for which the descriptor is to be calculated *@return The Covalent radius of the atom */ @Override public DescriptorValue calculate(IAtom atom, IAtomContainer container) { if (factory == null) try { factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/jmol_atomtypes.txt", container.getBuilder()); } catch (Exception exception) { return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult( Double.NaN), getDescriptorNames(), exception); } double covalentradius; try { String symbol = atom.getSymbol(); IAtomType type = factory.getAtomType(symbol); covalentradius = type.getCovalentRadius(); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult( covalentradius), getDescriptorNames()); } catch (Exception exception) { logger.debug(exception); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult( Double.NaN), getDescriptorNames(), exception); } }