Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduced a more explicit way to define the number of connections an…

…d allowed bond orders

Change-Id: I302bf94ffb1bba03a889035b58cc17e0fcac54ff
  • Loading branch information...
commit b2c052680f4ea88bc61989070d12190cbbca648a 1 parent deed120
@egonw authored
View
38 src/main/org/openscience/cdk/config/atomtypes/OWLAtomTypeHandler.java
@@ -27,9 +27,11 @@
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IAtomType;
+import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
+import org.openscience.cdk.tools.manipulator.BondManipulator;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
@@ -49,6 +51,10 @@
private String currentChars;
private List<IAtomType> atomTypes;
private IAtomType currentAtomType;
+ private int piBondCount;
+ private int neighborCount;
+ private Order maxBondOrder;
+ private double bondOrderSum;
private static IChemObjectBuilder builder;
@@ -92,17 +98,21 @@ public void endElement(String uri, String local, String raw) {
private void endAtomTypeElement(String local) {
if ("AtomType".equals(local)) {
atomTypes.add(currentAtomType);
+ currentAtomType.setProperty(CDKConstants.PI_BOND_COUNT, piBondCount);
+ currentAtomType.setFormalNeighbourCount(neighborCount);
+ if (maxBondOrder != Order.UNSET) currentAtomType.setMaxBondOrder(maxBondOrder);
+ if (bondOrderSum > 0.1) currentAtomType.setBondOrderSum(bondOrderSum);
} else if ("formalCharge".equals(local)) {
if (currentChars.charAt(0) == '+') {
currentChars = currentChars.substring(1);
}
currentAtomType.setFormalCharge(Integer.parseInt(currentChars));
} else if ("formalNeighbourCount".equals(local)) {
- currentAtomType.setFormalNeighbourCount(Integer.parseInt(currentChars));
+ neighborCount = Integer.parseInt(currentChars);
} else if ("lonePairCount".equals(local)) {
currentAtomType.setProperty(CDKConstants.LONE_PAIR_COUNT, Integer.parseInt(currentChars));
} else if ("piBondCount".equals(local)) {
- currentAtomType.setProperty(CDKConstants.PI_BOND_COUNT, Integer.parseInt(currentChars));
+ piBondCount = Integer.parseInt(currentChars);
}
}
@@ -119,9 +129,33 @@ private void startAtomTypeElement(String local, Attributes atts) {
if ("AtomType".equals(local)) {
currentAtomType = builder.newInstance(IAtomType.class, "H");
currentAtomType.setAtomTypeName(atts.getValue("rdf:ID"));
+ piBondCount = 0;
+ neighborCount = 0;
+ maxBondOrder = Order.UNSET;
+ bondOrderSum = 0.0;
} else if ("hasElement".equals(local)) {
String attrValue = atts.getValue("rdf:resource");
currentAtomType.setSymbol(attrValue.substring(attrValue.indexOf("#")+1));
+ } else if ("formalBondType".equals(local)) {
+ neighborCount++;
+ String attrValue = atts.getValue("rdf:resource");
+ String bondType = attrValue.substring(attrValue.indexOf("#")+1);
+ if ("single".equals(bondType)) {
+ maxBondOrder = BondManipulator.getMaximumBondOrder(maxBondOrder, Order.SINGLE);
+ bondOrderSum += 1.0;
+ } else if ("double".equals(bondType)) {
+ maxBondOrder = BondManipulator.getMaximumBondOrder(maxBondOrder, Order.DOUBLE);
+ piBondCount++;
+ bondOrderSum += 2.0;
+ } else if ("triple".equals(bondType)) {
+ maxBondOrder = BondManipulator.getMaximumBondOrder(maxBondOrder, Order.TRIPLE);
+ piBondCount = piBondCount + 2;
+ bondOrderSum += 3.0;
+ } else if ("quadruple".equals(bondType)) {
+ maxBondOrder = BondManipulator.getMaximumBondOrder(maxBondOrder, Order.QUADRUPLE);
+ piBondCount = piBondCount + 3;
+ bondOrderSum += 4.0;
+ } // else: should throw an exception
} else if ("hybridization".equals(local)) {
String attrValue = atts.getValue("rdf:resource");
String hybridization = attrValue.substring(attrValue.indexOf("#")+1);
View
13 src/main/org/openscience/cdk/dict/data/cdk-atom-types.owl
@@ -6,6 +6,7 @@
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY elem "http://cdk.sf.net/ontologies/elements#" >
<!ENTITY at "http://cdk.sf.net/ontologies/atomtypes#" >
+ <!ENTITY bo "http://cdk.sf.net/ontologies/bondorders#" >
<!ENTITY cdkat "http://cdk.sf.net/ontologies/atomtype/cdk#" >
]>
<rdf:RDF xmlns="&cdkat;" xml:base="&cdkat;"
@@ -42,6 +43,12 @@
<owl:Thing rdf:about="&at;sp3d2"/>
<owl:Thing rdf:about="&at;octahedral"/>
+ <!-- The formal bond types from &at; -->
+ <owl:Thing rdf:about="&at;single"/>
+ <owl:Thing rdf:about="&at;double"/>
+ <owl:Thing rdf:about="&at;triple"/>
+ <owl:Thing rdf:about="&at;quadruple"/>
+
<!-- The Elements from &elem; -->
<owl:Thing rdf:about="&elem;H"/>
<owl:Thing rdf:about="&elem;He"/>
@@ -175,8 +182,10 @@
<at:hybridization rdf:resource="&at;sp3"/>
<at:formalCharge>0</at:formalCharge>
<at:lonePairCount>0</at:lonePairCount>
- <at:formalNeighbourCount>4</at:formalNeighbourCount>
- <at:piBondCount>0</at:piBondCount>
+ <at:formalBondType rdf:resource="&bo;single"/>
+ <at:formalBondType rdf:resource="&bo;single"/>
+ <at:formalBondType rdf:resource="&bo;single"/>
+ <at:formalBondType rdf:resource="&bo;single"/>
</at:AtomType>
<at:AtomType rdf:ID="C.sp">
Please sign in to comment.
Something went wrong with that request. Please try again.