@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); } }
@Test public void testDiff() { IAtomType element1 = mock(IAtomType.class); IAtomType element2 = mock(IAtomType.class); when(element1.getHybridization()).thenReturn(PLANAR3); when(element2.getHybridization()).thenReturn(SP3); String result = AtomTypeDiff.diff(element1, element2); Assert.assertNotNull(result); Assert.assertNotSame(0, result.length()); assertContains(result, "AtomTypeDiff"); assertContains(result, "PLANAR3/SP3"); }
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 testSetHybridization_Null() { Hybridization hybridization = Hybridization.SP1; IAtomType atom = (IAtomType) newChemObject(); atom.setHybridization(hybridization); Assert.assertEquals(hybridization, atom.getHybridization()); atom.setHybridization(null); Assert.assertNull(atom.getHybridization()); }
@Test public void testSetHybridization_IAtomType_Hybridization() { Hybridization hybridization = Hybridization.SP1; IAtomType atom = (IAtomType) newChemObject(); atom.setHybridization(hybridization); Assert.assertEquals(hybridization, atom.getHybridization()); }
/** * 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(); } }
/** * 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_Hybridization() throws Exception { IAtomType at = (IAtomType) newChemObject(); at.setHybridization(Hybridization.PLANAR3); IAtomType clone = (IAtomType) at.clone(); at.setHybridization(Hybridization.SP1); Assert.assertEquals(Hybridization.PLANAR3, clone.getHybridization()); }
/** {@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; }
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; } } }
@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)); }
nC++; IAtomType matched = matcher.findMatchingAtomType(mol, atom); if (matched != null && matched.getHybridization() == IAtomType.Hybridization.SP3) { nCSP3++;
@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)); }
/** * This method calculates the hybridization of an atom. * *@param atom The IAtom for which the DescriptorValue is requested *@param container Parameter is the atom container. *@return The hybridization */ @Override public DescriptorValue calculate(IAtom atom, IAtomContainer container) { try { matched = CDKAtomTypeMatcher.getInstance(atom.getBuilder()).findMatchingAtomType(container, atom); } catch (CDKException e) { return getDummyDescriptorValue(e); } if (matched == null) { int atnum = container.indexOf(atom); return getDummyDescriptorValue(new CDKException("The matched atom type was null (atom number " + atnum + ") " + atom.getSymbol())); } Hybridization atomHybridization = matched.getHybridization(); IntegerResult result = new IntegerResult(atomHybridization == null ? 0 : atomHybridization.ordinal()); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, getDescriptorNames()); }
@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 (atomType.getHybridization() == null) { return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( (int) Double.NaN), // does that work?? getDescriptorNames(), new CDKException("Hybridization was null")); int hybridizationCDK = atomType.getHybridization().ordinal();