1515import java .util .Set ;
1616import java .util .stream .IntStream ;
1717
18+ import org .apache .commons .cli .CommandLine ;
19+ import org .apache .commons .cli .CommandLineParser ;
20+ import org .apache .commons .cli .DefaultParser ;
21+ import org .apache .commons .cli .HelpFormatter ;
22+ import org .apache .commons .cli .Option ;
23+ import org .apache .commons .cli .Options ;
24+ import org .apache .commons .cli .ParseException ;
1825import org .openscience .cdk .Atom ;
1926import org .openscience .cdk .DefaultChemObjectBuilder ;
2027import org .openscience .cdk .depict .DepictionGenerator ;
@@ -273,7 +280,6 @@ public static void initialDegrees(){
273280
274281 public static void build (String mol ) throws IOException , CloneNotSupportedException , CDKException {
275282 for (int i =0 ;i <firstSymbols .size ();i ++) {
276- System .out .println (firstSymbols .get (i )+" " +firstOccurrences .get (i ));
277283 for (int j =0 ;j <firstOccurrences .get (i );j ++) {
278284 atomContainer .addAtom (new Atom (firstSymbols .get (i )));
279285 }
@@ -737,7 +743,18 @@ public static int[][] forwardSubRow(int lInverse, int cInverse, int maximalX,int
737743 }
738744 //IAtomContainer molden= buildC(addHydrogens(mat2,hIndex));
739745 if (connectivityTest (hIndex ,addHydrogens (mat2 ,hIndex ))){
740- /**pWriter.println("canonical matrix"+" "+count);
746+ /**System.out.println("**************");
747+ for(int s=0;s<10;s++) {
748+ for(int k=0; k<s;k++) {
749+ System.out.print(" ");
750+ }
751+ for(int k=s+1; k<10;k++) {
752+ System.out.print(mat2[s][k]);
753+ }
754+ System.out.println();
755+ }
756+ System.out.println("**************");
757+ pWriter.println("canonical matrix"+" "+count);
741758 for(int s=0;s<6;s++) {
742759 for(int k=0; k<s;k++) {
743760 pWriter.print(" ");
@@ -747,8 +764,8 @@ public static int[][] forwardSubRow(int lInverse, int cInverse, int maximalX,int
747764 }
748765 pWriter.println();
749766 }**/
750- // IAtomContainer mol= buildC(addHydrogens(mat2,hIndex));
751- // outFile.write(mol);
767+ IAtomContainer mol = buildC (addHydrogens (mat2 ,hIndex ));
768+ outFile .write (mol );
752769 //depict(mol,filedir+count+".png");
753770 count ++;
754771 }
@@ -880,10 +897,8 @@ public static int nextCount(int i, int size, Integer[] degrees, ArrayList<Intege
880897 }
881898 return count ;
882899 }
883- public static void run (String molecularFormula , String filePath ) throws IOException , CDKException , CloneNotSupportedException {
900+ public static void run () throws IOException , CDKException , CloneNotSupportedException {
884901 long startTime = System .nanoTime ();
885- formula =molecularFormula ;
886- filedir =filePath ;
887902 getSymbolsOccurrences (formula );
888903 initialDegrees ();
889904 //initialPartition=occurrences;
@@ -929,24 +944,22 @@ public static List<int[]> distributeHydrogens(ArrayList<Integer> partition, int[
929944 public static void canonicalBlockbasedGeneratorDemo () throws IOException , CloneNotSupportedException , CDKException {
930945 size =initialDegrees .length ;
931946 List <int []> newDegrees = distributeHydrogens (firstOccurrences , firstDegrees );
947+ //System.out.println(initialPartition);
932948 //partitionList.add(0,initialPartition);
933949 /**int[] newDegrees = new int[6];
934950 newDegrees[0]=3;
935951 newDegrees[1]=3;
936952 newDegrees[2]=3;
937953 newDegrees[3]=3;
938954 newDegrees[4]=3;
939- newDegrees[5]=3;**/
940- // genStrip(newDegrees);
955+ newDegrees[5]=3;
956+ genStrip(newDegrees);**/
941957 for (int [] degree : newDegrees ) {
942958 partitionList .clear ();
943959 formerPermutations .clear ();
944960 //genDemo(degree);
945961 initialPartition =getPartition (degree ,occurrences );
946- System .out .println (Arrays .toString (degree )+" " +initialPartition );
947- System .out .println ("count" +" " +count );
948962 partitionList .add (0 ,initialPartition );
949- System .out .println ("hIndex" +" " +hIndex );
950963 genStrip (degree );
951964 }
952965 }
@@ -1507,10 +1520,62 @@ public static ArrayList<Integer> partitionCriteria(ArrayList<Integer> partEx, in
15071520 return partNew ;
15081521 }
15091522
1510- public static void main (String [] args ) throws IOException , CDKException , CloneNotSupportedException {
1511- //FileWriter fWriter = new FileWriter("C:\\Users\\mehme\\Desktop\\No-Backup Zone\\outputs\\output.txt");
1512- //pWriter = new PrintWriter(fWriter);
1513- run ("C3NO2SH7" ,"C:\\ Users\\ mehme\\ Desktop\\ No-Backup Zone\\ outputs\\ " );
1514- //pWriter.close();
1523+ private void parseArgs (String [] args ) throws ParseException , IOException , org .apache .commons .cli .ParseException {
1524+ Options options = setupOptions (args );
1525+ CommandLineParser parser = new DefaultParser ();
1526+ try {
1527+ CommandLine cmd = parser .parse (options , args );
1528+ MORGEN .formula = cmd .getOptionValue ("formula" );
1529+ MORGEN .filedir = cmd .getOptionValue ("filedir" );
1530+ if (cmd .hasOption ("verbose" )) MORGEN .verbose = true ;
1531+ } catch (ParseException e ) {
1532+ HelpFormatter formatter = new HelpFormatter ();
1533+ formatter .setOptionComparator (null );
1534+ String header = "\n Generates molecular structures for a given molecular formula."
1535+ + " The input is a molecular formula string."
1536+ + "For example 'C2OH4'."
1537+ +"For this version, the hydrogens should be kept at the end of the string."
1538+ + "Besides this formula, the directory is needed to be specified for the output"
1539+ + "file. \n \n " ;
1540+ String footer = "\n Please report issues at https://github.com/MehmetAzizYirik/AlgorithmicGroupTheory" ;
1541+ formatter .printHelp ( "java -jar AlgorithmicGroupTheory.jar" , header , options , footer , true );
1542+ throw new ParseException ("Problem parsing command line" );
1543+ }
1544+ }
1545+
1546+ private Options setupOptions (String [] args ){
1547+ Options options = new Options ();
1548+ Option formula = Option .builder ("f" )
1549+ .required (true )
1550+ .hasArg ()
1551+ .longOpt ("formula" )
1552+ .desc ("formula (required)" )
1553+ .build ();
1554+ options .addOption (formula );
1555+ Option verbose = Option .builder ("v" )
1556+ .required (false )
1557+ .longOpt ("verbose" )
1558+ .desc ("print message" )
1559+ .build ();
1560+ options .addOption (verbose );
1561+ Option filedir = Option .builder ("d" )
1562+ .required (true )
1563+ .hasArg ()
1564+ .longOpt ("filedir" )
1565+ .desc ("Creates and store the output txt file in the directory (required)" )
1566+ .build ();
1567+ options .addOption (filedir );
1568+ return options ;
1569+ }
1570+
1571+ public static void main (String [] arguments ) throws IOException , CDKException , CloneNotSupportedException {
1572+ MORGEN gen = new MORGEN ();
1573+ //String[] argument= {"-f","C4H8", "-d", "C:\\Users\\mehme\\Desktop\\", "-v"};
1574+ try {
1575+ gen .parseArgs (arguments );
1576+ MORGEN .run ();
1577+ } catch (Exception e ) {
1578+ if (MORGEN .verbose ) e .getCause ();
1579+ }
15151580 }
15161581}
0 commit comments