Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

only delete non-multibond H's; fixes JCP issue 8 #28

Closed
wants to merge 4 commits into from

3 participants

@rwst

this the fix premeditated on the mailing list allowing molecules H3C-H-CH3 to be cleaned without hiccup

the link to the JCP issue is JChemPaint/jchempaint#8

...openscience/cdk/layout/StructureDiagramGenerator.java
((6 lines not shown))
//IAtom[] atoms = shallowCopy.getAtoms();
- for (int i = 0; i < shallowCopy.getAtomCount(); i++) {
- IAtom curAtom = shallowCopy.getAtom(i);
- if (curAtom.getSymbol().equals("H")) {
- shallowCopy.removeAtomAndConnectedElectronContainers(curAtom);
- curAtom.setPoint2d(null);
+ for (IAtom curAtom : shallowCopy.atoms()) {
+ if (curAtom.getSymbol().equals("H")) {
+ int bondsFromCurAtom=0;
+ for (IBond bond : shallowCopy.bonds())
+ if(bond.contains (curAtom))
+ ++bondsFromCurAtom;
+ if (bondsFromCurAtom < 2) {
@rwst
rwst added a note

Done. Thanks for the hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@egonw
Owner

John, did you make signed of copies of these two patches?

@egonw
Owner

But since this is a bug fix for cdk-1.4.x, it also needs a unit test... I suggest a test that checks if the fully-connected starting structure, is still fully connected after the SDG call, pretty much the problem outlined in the JCP report...

@johnmay
Owner

No not yet. As you say a unit test would be good.

Did you change the commit back from using the manipulator ralf?

Thanks,
J

@egonw
Owner

John, I think he made an additional commit, see the pull request, which now has two commits...

This is the update commit: rwst/cdk@869829a

@johnmay
Owner

Ah, I remember now

@egonw
Owner

I have added a unit test:

https://github.com/egonw/cdk/commits/422-14x-middleHUnitTest

I also signed of Ralf's patches which fix the fail of this unit test.

@rwst rwst closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 8, 2012
  1. @rwst
  2. @rwst
Commits on Aug 9, 2012
  1. @rwst

    only remove H-X H-atoms

    rwst authored
Commits on Sep 20, 2012
  1. @rwst
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 9 deletions.
  1. +13 −9 src/main/org/openscience/cdk/layout/StructureDiagramGenerator.java
View
22 src/main/org/openscience/cdk/layout/StructureDiagramGenerator.java
@@ -25,8 +25,7 @@
*/
package org.openscience.cdk.layout;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
import javax.vecmath.Point2d;
import javax.vecmath.Vector2d;
@@ -260,14 +259,19 @@ public void generateExperimentalCoordinates(Vector2d firstBondVector) throws CDK
// first make a shallow copy: Atom/Bond references are kept
IMolecule original = molecule;
IMolecule shallowCopy = molecule.getBuilder().newInstance(IMolecule.class,molecule);
- // ok, delete H's from
+ // delete single-bonded H's from
//IAtom[] atoms = shallowCopy.getAtoms();
- for (int i = 0; i < shallowCopy.getAtomCount(); i++) {
- IAtom curAtom = shallowCopy.getAtom(i);
- if (curAtom.getSymbol().equals("H")) {
- shallowCopy.removeAtomAndConnectedElectronContainers(curAtom);
- curAtom.setPoint2d(null);
- }
+ Map<IAtom,Integer> single_h = new HashMap<IAtom,Integer>();
+ for (IBond curBond : shallowCopy.bonds()) {
+ boolean first = curBond.getAtom(0).getSymbol().equals("H");
+ boolean second = curBond.getAtom(1).getSymbol().equals("H");
+ if (first && !second) single_h.put(curBond.getAtom(0), 0);
+ if (!first && second) single_h.put(curBond.getAtom(1), 0);
+ }
+ for (IAtom curAtom : single_h.keySet()) {
+ if (shallowCopy.getConnectedBondsCount(curAtom) == 1) {
+ shallowCopy.removeAtomAndConnectedElectronContainers(curAtom);
+ }
}
// do layout on the shallow copy
molecule = shallowCopy;
Something went wrong with that request. Please try again.