private String getSphericalMatcher(IAtomType type) throws CDKException {//NOPMD return (String) type.getProperty(CDKConstants.SPHERICAL_MATCHER); }
private String getSphericalMatcher(IAtomType type) throws CDKException {//NOPMD return (String) type.getProperty(CDKConstants.SPHERICAL_MATCHER); }
/** * 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; }
@Test public void testSetRingSize_int() { int five = 5; IAtomType a = (IAtomType) newChemObject(); a.setProperty(CDKConstants.PART_OF_RING_OF_SIZE, five); Assert.assertEquals(five, ((Integer) a.getProperty(CDKConstants.PART_OF_RING_OF_SIZE)).intValue()); }
/** * 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); } }
@Test public void testSetChemicalGroupConstant_int() { int benzol = 6; IAtomType a = (IAtomType) newChemObject(); a.setProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT, benzol); Assert.assertEquals(benzol, ((Integer) a.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT)).intValue()); }
Object property = type.getProperty(CDKConstants.PI_BOND_COUNT); if (property != null && property instanceof Integer) { electronCount += ((Integer) property).intValue();
@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; }
atom.setCharge(value.doubleValue()); Object color = at.getProperty("org.openscience.cdk.renderer.color"); if (color != null) { atom.setProperty("org.openscience.cdk.renderer.color", color);
@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()); }
if (type.getProperty(CDKConstants.SINGLE_ELECTRON_COUNT) != null) { int count = countSingleElectrons(container, atom); if (count != type.getProperty(CDKConstants.SINGLE_ELECTRON_COUNT, Integer.class).intValue()) return false;
@Test public void testSetSphericalMatcher_String() { String hoseCode = "C-4;HHHC(;///***)"; IAtomType a = (IAtomType) newChemObject(); a.setProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT, hoseCode); Assert.assertEquals(hoseCode, a.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT)); }
@Test public void testReadAtomTypes_CDK() { OWLAtomTypeReader reader = new OWLAtomTypeReader(new StringReader(OWL_CONTENT)); Assert.assertNotNull(reader); List<IAtomType> types = reader.readAtomTypes(new ChemObject().getBuilder()); Assert.assertNotNull(types); Assert.assertEquals(1, types.size()); Object object = types.get(0); Assert.assertNotNull(object); Assert.assertTrue(object instanceof IAtomType); IAtomType atomType = (IAtomType) object; Assert.assertEquals("C", atomType.getSymbol()); Assert.assertEquals("C.sp3.0", atomType.getAtomTypeName()); Assert.assertEquals(0, atomType.getFormalCharge().intValue()); Assert.assertEquals(IAtomType.Hybridization.SP3, atomType.getHybridization()); Assert.assertEquals(4, atomType.getFormalNeighbourCount().intValue()); Assert.assertEquals(0, atomType.getProperty(CDKConstants.LONE_PAIR_COUNT)); Assert.assertEquals(0, atomType.getProperty(CDKConstants.PI_BOND_COUNT)); Assert.assertEquals(0, atomType.getProperty(CDKConstants.SINGLE_ELECTRON_COUNT)); }
@Test public void testReadAtomTypes_CDK() { String data = "<atomTypeList xmlns=\"http://www.xml-cml.org/schema/cml2/core\" \n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xsi:schemaLocation=\"http://www.xml-cml.org/schema/cml2/core ../../io/cml/data/cmlAll.xsd\"\n" + " id=\"mol2\" title=\"MOL2 AtomTypes\"> \n" + " \n" + " <atomType id=\"C.sp\">\n" + " <atom elementType=\"C\" formalCharge=\"0\">\n" + " <scalar dataType=\"xsd:integer\" dictRef=\"cdk:formalNeighbourCount\">2</scalar>\n" + " <scalar dataType=\"xsd:integer\" dictRef=\"cdk:lonePairCount\">0</scalar>\n" + " <scalar dataType=\"xsd:integer\" dictRef=\"cdk:piBondCount\">2</scalar>\n" + " </atom>\n" + " <scalar dataType=\"xsd:string\" dictRef=\"cdk:hybridization\">sp1</scalar>\n" + " </atomType> " + "</atomTypeList>"; AtomTypeReader reader = new AtomTypeReader(new StringReader(data)); Assert.assertNotNull(reader); List<IAtomType> types = reader.readAtomTypes(new ChemObject().getBuilder()); Assert.assertNotNull(types); Assert.assertEquals(1, types.size()); Object object = types.get(0); Assert.assertNotNull(object); Assert.assertTrue(object instanceof IAtomType); IAtomType atomType = (IAtomType) object; Assert.assertEquals(0, atomType.getFormalCharge().intValue()); Assert.assertEquals(IAtomType.Hybridization.SP1, atomType.getHybridization()); Assert.assertEquals(0, atomType.getProperty(CDKConstants.LONE_PAIR_COUNT)); Assert.assertEquals(2, atomType.getProperty(CDKConstants.PI_BOND_COUNT)); }
IAtomType atomType = (IAtomType) object; Assert.assertEquals("[CSP]-[0-4][-]?+;", atomType.getProperty(CDKConstants.SPHERICAL_MATCHER)); Assert.assertFalse(atomType.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR)); Assert.assertFalse(atomType.getFlag(CDKConstants.IS_HYDROGENBOND_DONOR)); Assert.assertEquals(3, atomType.getProperty(CDKConstants.PART_OF_RING_OF_SIZE)); Assert.assertEquals(3, atomType.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT));
ImmutableAtomType(IAtomType type) { this.element = type.getSymbol(); this.atomicNumber = type.getAtomicNumber(); this.naturalAbundance = type.getNaturalAbundance(); this.exactMass = type.getExactMass(); this.massNumber = type.getMassNumber(); this.formalCharge = type.getFormalCharge(); this.hybridization = type.getHybridization(); this.formalNeighbourCount = type.getFormalNeighbourCount(); this.identifier = type.getAtomTypeName(); this.maxBondOrder = type.getMaxBondOrder(); this.bondOrderSum = type.getBondOrderSum(); this.covalentRadius = type.getCovalentRadius(); this.flags = (short)type.getFlagValue(); this.properties = Collections.unmodifiableMap(type.getProperties()); if (type.getValency() != null) { this.electronValency = type.getValency(); } else { Integer piBondCount = type.getProperty(CDKConstants.PI_BOND_COUNT, Integer.class); if (piBondCount != null && formalNeighbourCount != null) { this.electronValency = piBondCount + formalNeighbourCount; } else { this.electronValency = null; } } }
ImmutableAtomType(IAtomType type) { this.element = type.getSymbol(); this.atomicNumber = type.getAtomicNumber(); this.naturalAbundance = type.getNaturalAbundance(); this.exactMass = type.getExactMass(); this.massNumber = type.getMassNumber(); this.formalCharge = type.getFormalCharge(); this.hybridization = type.getHybridization(); this.formalNeighbourCount = type.getFormalNeighbourCount(); this.identifier = type.getAtomTypeName(); this.maxBondOrder = type.getMaxBondOrder(); this.bondOrderSum = type.getBondOrderSum(); this.covalentRadius = type.getCovalentRadius(); this.flags = (short)type.getFlagValue(); this.properties = Collections.unmodifiableMap(type.getProperties()); if (type.getValency() != null) { this.electronValency = type.getValency(); } else { Integer piBondCount = type.getProperty(CDKConstants.PI_BOND_COUNT, Integer.class); if (piBondCount != null && formalNeighbourCount != null) { this.electronValency = piBondCount + formalNeighbourCount; } else { this.electronValency = null; } } }
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()); 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));