/** * 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(); } }
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; } } }
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())); } }
if ("X".equals(atomType.getAtomTypeName())) { atom.setAtomTypeName("X"); return; atom.setAtomTypeName(atomType.getAtomTypeName()); atom.setSymbol(atomType.getSymbol()); atom.setMaxBondOrder(atomType.getMaxBondOrder()); atom.setBondOrderSum(atomType.getBondOrderSum()); atom.setCovalentRadius(atomType.getCovalentRadius()); atom.setValency(atomType.getValency()); atom.setFormalCharge(atomType.getFormalCharge()); atom.setHybridization(atomType.getHybridization()); atom.setFormalNeighbourCount(atomType.getFormalNeighbourCount()); atom.setFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR, atomType.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR)); atom.setFlag(CDKConstants.IS_HYDROGENBOND_DONOR, atomType.getFlag(CDKConstants.IS_HYDROGENBOND_DONOR)); Object constant = atomType.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT); if (constant != null) { atom.setProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT, constant); if (atomType.getFlag(CDKConstants.ISAROMATIC)) atom.setFlag(CDKConstants.ISAROMATIC, atomType.getFlag(CDKConstants.ISAROMATIC)); Object color = atomType.getProperty("org.openscience.cdk.renderer.color"); if (color != null) { atom.setProperty("org.openscience.cdk.renderer.color", color); if (atomType.getAtomicNumber() != CDKConstants.UNSET) atom.setAtomicNumber(atomType.getAtomicNumber()); if (atomType.getExactMass() != CDKConstants.UNSET) atom.setExactMass(atomType.getExactMass());
@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()); }
atom.setSymbol(atomType.getSymbol()); atom.setMaxBondOrder(atomType.getMaxBondOrder()); atom.setBondOrderSum(atomType.getBondOrderSum()); atom.setCovalentRadius(atomType.getCovalentRadius()); atom.setHybridization(atomType.getHybridization()); Object color = atomType.getProperty("org.openscience.cdk.renderer.color"); if (color != null) { atom.setProperty("org.openscience.cdk.renderer.color", color); atom.setAtomicNumber(atomType.getAtomicNumber()); atom.setExactMass(atomType.getExactMass()); } catch (Exception exception) { logger.warn("Could not configure atom with unknown ID: ", atom, " + (id=", atom.getAtomTypeName(), ")");
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); } }
atom.setSymbol(at.getSymbol()); atom.setAtomTypeName(at.getAtomTypeName()); atom.setFormalNeighbourCount(at.getFormalNeighbourCount()); key = "vdw" + ID; data = (List) parameterSet.get(key); atom.setCharge(value.doubleValue()); Object color = at.getProperty("org.openscience.cdk.renderer.color"); if (color != null) { atom.setProperty("org.openscience.cdk.renderer.color", color); if (at.getAtomicNumber() != 0) { atom.setAtomicNumber(at.getAtomicNumber()); if (at.getExactMass() > 0.0) { atom.setExactMass(at.getExactMass());
@Test public void testAtomType_String_String() { IAtomType at = new AtomType("C4", "C"); Assert.assertEquals("C", at.getSymbol()); Assert.assertEquals("C4", at.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 testSetMMFF94Parameters() throws Exception { forceFieldConfigurator.setMMFF94Parameters(DefaultChemObjectBuilder.getInstance()); assertNotNull(forceFieldConfigurator.getParameterSet()); List<IAtomType> atomtypeList = forceFieldConfigurator.getAtomTypes(); IAtomType atomtype4 = atomtypeList.get(4); assertEquals("CO2M", atomtype4.getAtomTypeName()); assertEquals(6, (int) atomtype4.getAtomicNumber()); assertEquals(3, (int) atomtype4.getFormalNeighbourCount()); assertEquals(12, (int) atomtype4.getMassNumber()); }
if (couldMatchAtomType(atom, bondOrderSum, maxBondOrder, type)) { logger.debug("This type matches: ", type); int formalNeighbourCount = type.getFormalNeighbourCount(); if (type.getHybridization() == CDKConstants.UNSET) { missingHydrogens = (int) (type.getBondOrderSum() - bondOrderSum); } else if (type.getHybridization() == Hybridization.SP3) { missingHydrogens = formalNeighbourCount - neighbourCount; } else if (type.getHybridization() == Hybridization.SP2) { missingHydrogens = formalNeighbourCount - neighbourCount; } else if (type.getHybridization() == Hybridization.SP1) { missingHydrogens = formalNeighbourCount - neighbourCount; } else { missingHydrogens = (int) (type.getBondOrderSum() - bondOrderSum);
/** * 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; }
public boolean hasPerfectConfiguration(IAtom atom, IAtomContainer ac) throws CDKException { double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return true; logger.debug("*** Checking for perfect configuration ***"); try { logger.debug("Checking configuration of atom " + ac.indexOf(atom)); logger.debug("Atom has bondOrderSum = " + bondOrderSum); logger.debug("Atom has max = " + bondOrderSum); } catch (Exception exc) { } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum == atomTypes[f].getBondOrderSum() && maxBondOrder == atomTypes[f].getMaxBondOrder()) { try { logger.debug("Atom " + ac.indexOf(atom) + " has perfect configuration"); } catch (Exception exc) { } return true; } } try { logger.debug("*** Atom " + ac.indexOf(atom) + " has imperfect configuration ***"); } catch (Exception exc) { } return false; }
/** {@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; }
IAtomType type = matcher.findMatchingAtomType(container, atom); if (type != null && !type.getAtomTypeName().equals("X") && type.getFormalNeighbourCount() != null) { type.getFormalNeighbourCount() - connectedAtomCount, atom.getImplicitHydrogenCount()}); atom.setImplicitHydrogenCount(type.getFormalNeighbourCount() - connectedAtomCount);
@Test public void testGetAtomTypeName() { IAtomType at = (IAtomType) newChemObject(); at.setAtomTypeName("C4"); Assert.assertEquals("C4", at.getAtomTypeName()); }
@Test public void testSetMM2Parameters() throws CDKException { forceFieldConfigurator.setMM2Parameters(DefaultChemObjectBuilder.getInstance()); assertNotNull(forceFieldConfigurator.getParameterSet()); List<IAtomType> atomtypeList = forceFieldConfigurator.getAtomTypes(); IAtomType atomtype1 = atomtypeList.get(1); assertEquals("Csp2", atomtype1.getAtomTypeName()); assertEquals(6, (int) atomtype1.getAtomicNumber()); assertEquals(12, (int) atomtype1.getMassNumber()); }
@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)); }
@Test public void testDifference() { IAtomType element1 = mock(IAtomType.class); IAtomType element2 = mock(IAtomType.class); when(element1.getHybridization()).thenReturn(PLANAR3); when(element2.getHybridization()).thenReturn(SP3); IDifference difference = AtomTypeDiff.difference(element1, element2); Assert.assertNotNull(difference); } }