From: Christoph S. <ste...@us...> - 2002-05-23 09:48:45
|
Update of /cvsroot/cdk/cdk/org/openscience/cdk/structgen In directory usw-pr-cvs1:/tmp/cvs-serv17783/structgen Modified Files: VicinitySampler.java Log Message: Bugfixes for the VicinitySampler Index: VicinitySampler.java =================================================================== RCS file: /cvsroot/cdk/cdk/org/openscience/cdk/structgen/VicinitySampler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** VicinitySampler.java 21 May 2002 13:45:50 -0000 1.1 --- VicinitySampler.java 23 May 2002 09:48:42 -0000 1.2 *************** *** 52,55 **** --- 52,56 ---- public boolean debug = false; private int[] correctBondOrderSums; + int molCounter = 0; /** *************** *** 83,88 **** if(debug) System.out.println("RandomGenerator->mutate() Start"); Vector structures = new Vector(); int nrOfAtoms = ac.getAtomCount(); - int x1 = 0, x2 = 0, y1 = 0, y2 = 0; double a11 = 0, a12 = 0, a22 = 0, a21 = 0; double b11 = 0, lowerborder = 0, upperborder = 0; --- 84,89 ---- if(debug) System.out.println("RandomGenerator->mutate() Start"); Vector structures = new Vector(); + ConnectivityChecker conCheck = new ConnectivityChecker(); int nrOfAtoms = ac.getAtomCount(); double a11 = 0, a12 = 0, a22 = 0, a21 = 0; double b11 = 0, lowerborder = 0, upperborder = 0; *************** *** 92,95 **** --- 93,97 ---- double[] cmax = new double[4]; double[] cmin = new double[4]; + AtomContainer newAc = (AtomContainer)ac.clone(); Atom ax1 = null, ax2 = null, ay1 = null, ay2 = null; *************** *** 99,118 **** /* We need at least two non-zero bonds in order to be successful */ int nonZeroBondsCounter = 0; ! for (x1 = 0; x1 < nrOfAtoms; x1++) { ! for (x2 = x1 + 1; x2 < nrOfAtoms; x2++) { ! for (y1 = x2 + 1; y1 < nrOfAtoms; y1++) { ! for (y2 = y1 + 1; y2 < nrOfAtoms; y2++) { nonZeroBondsCounter = 0; ! ax1 = ac.getAtomAt(x1); ! ay1 = ac.getAtomAt(y1); ! ax2 = ac.getAtomAt(x2); ! ay2 = ac.getAtomAt(y2); /* Get four bonds for these four atoms */ ! b1 = ac.getBond(ax1, ay1); if (b1 != null) { --- 101,124 ---- /* We need at least two non-zero bonds in order to be successful */ int nonZeroBondsCounter = 0; ! boolean changed = false; ! for (int x1 = 0; x1 < nrOfAtoms; x1++) { ! for (int x2 = x1 + 1; x2 < nrOfAtoms; x2++) { ! for (int y1 = x2 + 1; y1 < nrOfAtoms; y1++) { ! for (int y2 = y1 + 1; y2 < nrOfAtoms; y2++) { + if (changed) newAc = (AtomContainer)ac.clone(); nonZeroBondsCounter = 0; ! ax1 = newAc.getAtomAt(x1); ! ay1 = newAc.getAtomAt(y1); ! ax2 = newAc.getAtomAt(x2); ! ay2 = newAc.getAtomAt(y2); ! ! /* Get four bonds for these four atoms */ ! b1 = newAc.getBond(ax1, ay1); if (b1 != null) { *************** *** 125,129 **** } ! b2 = ac.getBond(ax1, ay2); if (b2 != null) { --- 131,135 ---- } ! b2 = newAc.getBond(ax1, ay2); if (b2 != null) { *************** *** 136,140 **** } ! b3 = ac.getBond(ax2, ay1); if (b3 != null) { --- 142,146 ---- } ! b3 = newAc.getBond(ax2, ay1); if (b3 != null) { *************** *** 147,151 **** } ! b4 = ac.getBond(ax2, ay2); if (b4 != null) { --- 153,157 ---- } ! b4 = newAc.getBond(ax2, ay2); if (b4 != null) { *************** *** 179,184 **** b21 = a11 + a21 - b11; b22 = a22 - a11 + b11; ! change(ac, ax1, ay1, ax2, ay2, b1, b2, b3, b4, b11, b12, b21, b22); ! structures.add(ac.clone()); } } --- 185,199 ---- b21 = a11 + a21 - b11; b22 = a22 - a11 + b11; ! System.out.println("Trying atom combination : " + x1 + ":" + x2 + ":"+ y1 + ":"+ y2); ! changed = true; ! newAc = change(newAc, ax1, ay1, ax2, ay2, b1, b2, b3, b4, b11, b12, b21, b22); ! if (conCheck.isConnected(newAc)) ! { ! structures.add(newAc); ! } ! else ! { ! System.out.println("not connected"); ! } } } *************** *** 230,239 **** } ! private void change(AtomContainer ac, Atom ax1, Atom ay1, Atom ax2, Atom ay2, Bond b1, Bond b2, Bond b3, Bond b4, double b11, double b12, double b21, double b22) { if (b11 > 0) { if (b1 == null) { b1 = new Bond(ax1, ay1, b11); ac.addBond(b1); --- 245,269 ---- } ! private AtomContainer change(AtomContainer ac, Atom ax1, Atom ay1, Atom ax2, Atom ay2, Bond b1, Bond b2, Bond b3, Bond b4, double b11, double b12, double b21, double b22) { + int x1 = -1, x2 = -1, y1 = -1, y2 = -1; + System.out.println("About to make modification " + molCounter); + molCounter ++; + try + { + x1 = ac.getAtomNumber(ax1); + x2 = ac.getAtomNumber(ax2); + y1 = ac.getAtomNumber(ay1); + y2 = ac.getAtomNumber(ay2); + } + catch(Exception exc) + { + exc.printStackTrace(); + } if (b11 > 0) { if (b1 == null) { + System.out.println("no bond " + x1 + "-" + y1 + ". Adding it with order " + b11); b1 = new Bond(ax1, ay1, b11); ac.addBond(b1); *************** *** 247,250 **** --- 277,281 ---- { ac.removeBond(b1); + System.out.println("removing bond " + x1 + "-" + y1); } *************** *** 253,256 **** --- 284,288 ---- if (b2 == null) { + System.out.println("no bond " + x1 + "-" + y2 + ". Adding it with order " + b12); b2 = new Bond(ax1, ay2, b12); ac.addBond(b2); *************** *** 264,267 **** --- 296,300 ---- { ac.removeBond(b2); + System.out.println("removing bond " + x1 + "-" + y2); } *************** *** 270,273 **** --- 303,307 ---- if (b3 == null) { + System.out.println("no bond " + x2 + "-" + y1 + ". Adding it with order " + b21); b3 = new Bond(ax2, ay1, b21); ac.addBond(b3); *************** *** 281,284 **** --- 315,319 ---- { ac.removeBond(b3); + System.out.println("removing bond " + x2 + "-" + y1); } *************** *** 287,290 **** --- 322,326 ---- if (b4 == null) { + System.out.println("no bond " + x2 + "-" + y2 + ". Adding it with order " + b22); b4 = new Bond(ax2, ay2, b22); ac.addBond(b4); *************** *** 298,303 **** { ac.removeBond(b4); } ! } --- 334,340 ---- { ac.removeBond(b4); + System.out.println("removing bond " + x2 + "-" + y2); } ! return ac; } |