@@ -70,10 +70,13 @@ public class MORGEN {
7070 valences = new HashMap <String , Integer >();
7171
7272 valences .put ("C" , 4 );
73- valences .put ("N" , 5 );
73+ //valences.put("N", 5);
74+ valences .put ("N" , 3 );
7475 valences .put ("O" , 2 );
75- valences .put ("S" , 6 );
76- valences .put ("P" , 5 );
76+ //valences.put("S", 6);
77+ valences .put ("S" , 2 );
78+ //valences.put("P", 5);
79+ valences .put ("P" , 3 );
7780 valences .put ("F" , 1 );
7881 valences .put ("I" , 1 );
7982 valences .put ("Cl" , 1 );
@@ -270,6 +273,7 @@ public static void initialDegrees(){
270273
271274 public static void build (String mol ) throws IOException , CloneNotSupportedException , CDKException {
272275 for (int i =0 ;i <firstSymbols .size ();i ++) {
276+ System .out .println (firstSymbols .get (i )+" " +firstOccurrences .get (i ));
273277 for (int j =0 ;j <firstOccurrences .get (i );j ++) {
274278 atomContainer .addAtom (new Atom (firstSymbols .get (i )));
275279 }
@@ -548,6 +552,9 @@ public static void genStrip(int[] degreeList) throws IOException, CloneNotSuppor
548552 z =findZ (r );
549553 while (flag ) {
550554 int [][] mat =nextStep (A ,indices ,callForward );
555+ if (!flag ) {
556+ break ;
557+ }
551558 indices =successor (indices ,max .length );
552559 callForward =true ;
553560 nextStep (mat ,indices ,callForward );
@@ -662,8 +669,7 @@ public static boolean backwardCriteria(int x, int lInverse, int l) {
662669
663670 public static int [][] backwardDemo (int [][] A , int [] indices , boolean callForward ) throws IOException , CloneNotSupportedException , CDKException {
664671 int i =indices [0 ];
665- int j =indices [1 ];
666-
672+ int j =indices [1 ];
667673 if (i ==0 && j ==1 ) {
668674 flag =false ;
669675 return A ;
@@ -675,7 +681,10 @@ public static int[][] backwardDemo(int[][] A, int[] indices, boolean callForward
675681 int x = A [i ][j ];
676682 int l2 = LInverse (degrees ,i ,j ,A );
677683 int c2 = CInverse (degrees ,i ,j ,A );
678- if (x >0 && (backwardCriteria (x ,l2 ,L [i ][j ]) && backwardCriteria (x ,c2 ,C [i ][j ]))){
684+ /**
685+ * I changed in backcriteria from x to x-1 but then I had error c6h6 was 98 not 217
686+ */
687+ if (x >0 && (backwardCriteria ((x ),l2 ,L [i ][j ]) && backwardCriteria ((x ),c2 ,C [i ][j ]))){
679688 A [i ][j ]=(x -1 );
680689 A [j ][i ]=(x -1 );
681690 indices = successor (indices ,max .length );
@@ -696,6 +705,7 @@ public static int[][] forwardRow(int[][] A, int[] indices, boolean callForward)
696705 int cInverse = CInverse (degrees ,i ,j ,A );
697706 int minimal = Math .min (max [i ][j ],Math .min (lInverse ,cInverse ));
698707
708+
699709 /**
700710 * First step in the forward method.
701711 */
@@ -726,13 +736,13 @@ public static int[][] forwardSubRow(int lInverse, int cInverse, int maximalX,int
726736 }
727737 }
728738 //IAtomContainer molden= buildC(addHydrogens(mat2,hIndex));
729- if (connectivityTest (hIndex ,addHydrogens (mat2 ,hIndex ))){
730- // pWriter.println("canonical matrix"+" "+count);
731- /** for(int s=0;s<4 ;s++) {
739+ if (connectivityTest (hIndex ,addHydrogens (mat2 ,hIndex ))){
740+ /** pWriter.println("canonical matrix"+" "+count);
741+ for(int s=0;s<6 ;s++) {
732742 for(int k=0; k<s;k++) {
733743 pWriter.print(" ");
734744 }
735- for(int k=s+1; k<4 ;k++) {
745+ for(int k=s+1; k<6 ;k++) {
736746 pWriter.print(mat2[s][k]);
737747 }
738748 pWriter.println();
@@ -745,7 +755,7 @@ public static int[][] forwardSubRow(int lInverse, int cInverse, int maximalX,int
745755 }
746756 callForward =false ;
747757 return nextStep (A , indices , callForward );
748- }else {
758+ }else {
749759 if (indices [0 ]==findZ (r ) && indices [1 ]==(max .length -1 )) {
750760 callForward =canonicalTest (A );
751761 if (callForward ) {
@@ -762,7 +772,7 @@ public static int[][] forwardSubRow(int lInverse, int cInverse, int maximalX,int
762772 return nextStep (A , indices , true );
763773 }
764774 }
765- }
775+ }
766776 }else {
767777 callForward =false ;
768778 return nextStep (A , indices ,callForward );
@@ -820,7 +830,19 @@ public static int CInverse(int[] degrees, int i, int j, int[][]A) {
820830 * Main functions
821831 */
822832
823- public static ArrayList <Integer > getPartition (int [] degrees ){
833+ public static ArrayList <Integer > getPartition (int [] degrees , ArrayList <Integer > partition ){
834+ ArrayList <Integer > newPartition = new ArrayList <Integer >();
835+ int i =0 ;
836+ for (Integer p :partition ) {
837+ Integer [] subArray = getBlocks (degrees ,i ,p +i );
838+ newPartition .addAll (getSubPartition (subArray ));
839+ i =i +p ;
840+ }
841+ return newPartition ;
842+ }
843+
844+
845+ public static ArrayList <Integer > getSubPartition (Integer [] degrees ){
824846 ArrayList <Integer > partition = new ArrayList <Integer >();
825847 int i =0 ;
826848 int size = degrees .length ;
@@ -838,7 +860,7 @@ public static ArrayList<Integer> getPartition(int[] degrees){
838860 return partition ;
839861 }
840862
841- public static int nextCount (int i , int size , int [] degrees , ArrayList <Integer > partition ) {
863+ public static int nextCount (int i , int size , Integer [] degrees , ArrayList <Integer > partition ) {
842864 int count =1 ;
843865 if (i ==(size -1 )) {
844866 partition .add (1 );
@@ -865,7 +887,7 @@ public static void run(String molecularFormula, String filePath) throws IOExcept
865887 getSymbolsOccurrences (formula );
866888 initialDegrees ();
867889 //initialPartition=occurrences;
868- // build(formula);
890+ build (formula );
869891 outFile = new SDFWriter (new FileWriter (filedir +"output.sdf" ));
870892 canonicalBlockbasedGeneratorDemo ();
871893 //if(verbose) System.out.println("The number of structures is: "+count);
@@ -920,8 +942,11 @@ public static void canonicalBlockbasedGeneratorDemo() throws IOException, CloneN
920942 partitionList .clear ();
921943 formerPermutations .clear ();
922944 //genDemo(degree);
923- initialPartition =getPartition (degree );
945+ initialPartition =getPartition (degree ,occurrences );
946+ System .out .println (Arrays .toString (degree )+" " +initialPartition );
947+ System .out .println ("count" +" " +count );
924948 partitionList .add (0 ,initialPartition );
949+ System .out .println ("hIndex" +" " +hIndex );
925950 genStrip (degree );
926951 }
927952 }
@@ -1485,7 +1510,7 @@ public static ArrayList<Integer> partitionCriteria(ArrayList<Integer> partEx, in
14851510 public static void main (String [] args ) throws IOException , CDKException , CloneNotSupportedException {
14861511 //FileWriter fWriter = new FileWriter("C:\\Users\\mehme\\Desktop\\No-Backup Zone\\outputs\\output.txt");
14871512 //pWriter = new PrintWriter(fWriter);
1488- run ("C4OH10 " ,"C:\\ Users\\ mehme\\ Desktop\\ No-Backup Zone\\ outputs\\ " );
1513+ run ("C3NO2SH7 " ,"C:\\ Users\\ mehme\\ Desktop\\ No-Backup Zone\\ outputs\\ " );
14891514 //pWriter.close();
14901515 }
14911516}
0 commit comments