Skip to content

Commit

Permalink
Introduced a more explicit way to define the number of connections an…
Browse files Browse the repository at this point in the history
…d allowed bond orders

Change-Id: I302bf94ffb1bba03a889035b58cc17e0fcac54ff
Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
egonw committed Oct 7, 2012
1 parent 4e45c7d commit 492a9cd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -49,6 +51,10 @@ public class OWLAtomTypeHandler extends DefaultHandler {
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;

Expand Down Expand Up @@ -92,19 +98,23 @@ 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 ("singleElectronCount".equals(local)) {
currentAtomType.setProperty(CDKConstants.SINGLE_ELECTRON_COUNT, Integer.parseInt(currentChars));
} else if ("piBondCount".equals(local)) {
currentAtomType.setProperty(CDKConstants.PI_BOND_COUNT, Integer.parseInt(currentChars));
piBondCount = Integer.parseInt(currentChars);
}
}

Expand All @@ -121,9 +131,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);
Expand Down
13 changes: 11 additions & 2 deletions src/main/org/openscience/cdk/dict/data/cdk-atom-types.owl
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit 492a9cd

Please sign in to comment.