private static void serializeAtomTypeFields(Model model, Resource rdfObject, IAtomType type) { serializeIsotopeFields(model, rdfObject, type); if (type.getHybridization() != null) { Hybridization hybrid = type.getHybridization(); if (HYBRID_TO_RESOURCE.containsKey(hybrid)) model.add(rdfObject, CDK.HASHYBRIDIZATION, HYBRID_TO_RESOURCE.get(hybrid)); } if (type.getAtomTypeName() != null) { model.add(rdfObject, CDK.HASATOMTYPENAME, type.getAtomTypeName()); } if (type.getFormalCharge() != null) { model.add(rdfObject, CDK.HASFORMALCHARGE, type.getFormalCharge().toString()); } if (type.getMaxBondOrder() != null) { model.add(rdfObject, CDK.HASMAXBONDORDER, order2Resource(type.getMaxBondOrder())); } }
private static void serializeAtomTypeFields(Model model, Resource rdfObject, IAtomType type) { serializeIsotopeFields(model, rdfObject, type); if (type.getHybridization() != null) { Hybridization hybrid = type.getHybridization(); if (HYBRID_TO_RESOURCE.containsKey(hybrid)) model.add(rdfObject, CDK.HASHYBRIDIZATION, HYBRID_TO_RESOURCE.get(hybrid)); } if (type.getAtomTypeName() != null) { model.add(rdfObject, CDK.HASATOMTYPENAME, type.getAtomTypeName()); } if (type.getFormalCharge() != null) { model.add(rdfObject, CDK.HASFORMALCHARGE, type.getFormalCharge().toString()); } if (type.getMaxBondOrder() != null) { model.add(rdfObject, CDK.HASMAXBONDORDER, order2Resource(type.getMaxBondOrder())); } }
@Test public void testDefaultFormalCharge() { IAtomType atomType = (IAtomType) newChemObject(); Assert.assertEquals(0, atomType.getFormalCharge().intValue()); } }
@Test public void testSetFormalCharge_Integer() { int charge = 1; IAtomType a = (IAtomType) newChemObject(); a.setFormalCharge(charge); Assert.assertEquals(charge, a.getFormalCharge().intValue()); }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instanceof * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instance of * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instanceof * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * Method to test the clone() method */ @Test public void testClone_FormalCharge() throws Exception { IAtomType at = (IAtomType) newChemObject(); at.setFormalCharge(1); IAtomType clone = (IAtomType) at.clone(); at.setFormalCharge(2); Assert.assertEquals(1, clone.getFormalCharge().intValue()); }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instance of * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
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; } } }
for (int j = 0; j < atomTypes.length; j++) { IAtomType type = atomTypes[j]; if (Objects.equals(atom.getFormalCharge(), type.getFormalCharge())) { foundMatchingAtomType = true; if (bos == type.getBondOrderSum()) {
@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)); }
/** * Determines if the atom can be of type AtomType. That is, it sees if this * AtomType only differs in bond orders, or implicit hydrogen count. */ public boolean couldMatchAtomType(IAtom atom, double bondOrderSum, IBond.Order maxBondOrder, IAtomType type) { logger.debug("couldMatchAtomType: ... matching atom ", atom, " vs ", type); int hcount = atom.getImplicitHydrogenCount(); int charge = atom.getFormalCharge(); if (charge == type.getFormalCharge()) { logger.debug("couldMatchAtomType: formal charge matches..."); // if (atom.getHybridization() == type.getHybridization()) { // logger.debug("couldMatchAtomType: hybridization is OK..."); if (bondOrderSum + hcount <= type.getBondOrderSum()) { logger.debug("couldMatchAtomType: bond order sum is OK..."); if (!BondManipulator.isHigherOrder(maxBondOrder, type.getMaxBondOrder())) { logger.debug("couldMatchAtomType: max bond order is OK... We have a match!"); return true; } } else { logger.debug("couldMatchAtomType: no match", "" + (bondOrderSum + hcount), " > ", "" + type.getBondOrderSum()); } // } } else { logger.debug("couldMatchAtomType: formal charge does NOT match..."); } logger.debug("couldMatchAtomType: No Match"); return false; }
/** * Determines if the atom can be of type AtomType. That is, it sees if this * AtomType only differs in bond orders, or implicit hydrogen count. */ public boolean couldMatchAtomType(IAtom atom, double bondOrderSum, IBond.Order maxBondOrder, IAtomType type) { logger.debug("couldMatchAtomType: ... matching atom ", atom, " vs ", type); int hcount = atom.getImplicitHydrogenCount(); int charge = atom.getFormalCharge(); if (charge == type.getFormalCharge()) { logger.debug("couldMatchAtomType: formal charge matches..."); // if (atom.getHybridization() == type.getHybridization()) { // logger.debug("couldMatchAtomType: hybridization is OK..."); if (bondOrderSum + hcount <= type.getBondOrderSum()) { logger.debug("couldMatchAtomType: bond order sum is OK..."); if (!BondManipulator.isHigherOrder(maxBondOrder, type.getMaxBondOrder())) { logger.debug("couldMatchAtomType: max bond order is OK... We have a match!"); return true; } } else { logger.debug("couldMatchAtomType: no match", "" + (bondOrderSum + hcount), " > ", "" + type.getBondOrderSum()); } // } } else { logger.debug("couldMatchAtomType: formal charge does NOT match..."); } logger.debug("couldMatchAtomType: No Match"); return false; }
@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)); }
Assert.assertEquals("Hybridization does not match", atom.getHybridization(), matched.getHybridization()); if (atom.getFormalCharge() != CDKConstants.UNSET && matched.getFormalCharge() != CDKConstants.UNSET) { Assert.assertEquals("Formal charge does not match", atom.getFormalCharge(), matched.getFormalCharge());
@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 (atom.getValency() == CDKConstants.UNSET && atomType.getValency() != CDKConstants.UNSET) atom.setValency(atomType.getValency()); if (atom.getFormalCharge() == CDKConstants.UNSET && atomType.getFormalCharge() != CDKConstants.UNSET) atom.setFormalCharge(atomType.getFormalCharge()); if (atom.getHybridization() == CDKConstants.UNSET && atomType.getHybridization() != CDKConstants.UNSET) atom.setHybridization(atomType.getHybridization());
.addChild(DoubleDifference.construct("BOS", firstElem.getBondOrderSum(), secondElem.getBondOrderSum())); totalDiff .addChild(IntegerDifference.construct("FC", firstElem.getFormalCharge(), secondElem.getFormalCharge())); totalDiff.addChild(AtomTypeHybridizationDifference.construct("H", firstElem.getHybridization(), secondElem.getHybridization()));