00001
00014
00015
00016
00017
00018
00019
00020 #include "common.h"
00021 #include "atoms.h"
00022 #include "atoms_chain.h"
00023 #include "atoms_part.h"
00024
00025 #include "partitionner.h"
00026
00027
00028
00029
00030
00031 static int C_paraNum = 0;
00032 static int C_fileNum = 0;
00033 static File C_fileTab[C_FILENBR] = {
00034 { "-", NULL, "r" },
00035 { "-", NULL, "w" },
00036 { "-", NULL, "w" },
00037 { "-", NULL, "w" },
00038 { "-", NULL, "w" } };
00039
00040 static const char * C_usageList[] = {
00041 "main_part <number of parts> <overlap distance> <cut distance> <options> <atoms file> <partition file>",
00042 " -o<type> : Partition format",
00043 " q : QC partition format",
00044 " i : QCi partition format",
00045 " s : Scotch format",
00046 " -s<file> : Output topology to <file>, in Scotch format",
00047 " -g<file> : Output geometry to <file>, in Scotch format",
00048 " -n<file> : Output neighbor topology to <file>, in Scotch format",
00049 " -h : Display this help",
00050 NULL };
00051
00052
00053
00054
00055
00056
00057
00058 int
00059 main (argc, argv)
00060 int argc;
00061 char * argv[];
00062 {
00063 double dsovval;
00064 double dscuval;
00065 FLOAT dsnbval;
00066 INT atomnum;
00067 AtomsList listdat;
00068 AtomsGraph grafdat;
00069 AtomsGraph grasdat;
00070 AtomsGraph grandat;
00071 INT * restrict velotab;
00072 AtomsPart partdat;
00073 INT * restrict parttab;
00074 INT partnbr;
00075 int flag;
00076 int pfmt;
00077 double d[3];
00078 int i;
00079
00080 errorProg ("main_part");
00081
00082 flag = C_FLAGDEFAULT;
00083 pfmt = C_PFMTSCOTCH;
00084 d[0] = 2;
00085 d[1] = 3;
00086 d[2] = 2;
00087
00088 if ((argc >= 2) && ((argv[1][0] == '?') ||
00089 ( (argv[1][0] == '-') && (argv[1][1] == 'h') ))) {
00090 usagePrint (stdout, C_usageList);
00091 return (0);
00092 }
00093
00094 for (i = 0; i < C_FILENBR; i ++)
00095 C_fileTab[i].pntr = (C_fileTab[i].mode[0] == 'r') ? stdin : stdout;
00096 for (i = 1; i < argc; i ++) {
00097 if ((argv[i][0] != '+') &&
00098 ((argv[i][0] != '-') || (argv[i][1] == '\0'))) {
00099 if (C_paraNum < 3) {
00100 if ((d[C_paraNum ++] = atof (argv[i])) <= 0.0L) {
00101 errorPrint ("main: invalid dimension (\"%s\")", argv[i]);
00102 return (1);
00103 }
00104 continue;
00105 }
00106 if (C_fileNum < C_FILEARGNBR)
00107 C_fileTab[C_fileNum ++].name = argv[i];
00108 else {
00109 errorPrint ("main: too many file names given");
00110 return (1);
00111 }
00112 }
00113 else {
00114 switch (argv[i][1]) {
00115 case 'G' :
00116 case 'g' :
00117 flag |= C_FLAGGEOOUT;
00118 if (argv[i][2] != '\0')
00119 C_filenamegeoout = &argv[i][2];
00120 break;
00121 case 'H' :
00122 case 'h' :
00123 usagePrint (stdout, C_usageList);
00124 return (0);
00125 case 'N' :
00126 case 'n' :
00127 flag |= C_FLAGNGBOUT;
00128 if (argv[i][2] != '\0')
00129 C_filenamengbout = &argv[i][2];
00130 break;
00131 case 'S' :
00132 case 's' :
00133 flag |= C_FLAGSRCOUT;
00134 if (argv[i][2] != '\0')
00135 C_filenamesrcout = &argv[i][2];
00136 break;
00137 case 'O' :
00138 case 'o' :
00139 switch (argv[i][2]) {
00140 case 'I' :
00141 case 'i' :
00142 pfmt = C_PFMTQCI;
00143 break;
00144 case 'Q' :
00145 case 'q' :
00146 pfmt = C_PFMTQC;
00147 break;
00148 case 'S' :
00149 case 's' :
00150 pfmt = C_PFMTSCOTCH;
00151 break;
00152 default :
00153 errorPrint ("main: invalid output format type (\"%c\")", argv[i][2]);
00154 return (1);
00155 }
00156 break;
00157 default :
00158 errorPrint ("main: unprocessed option (\"%s\")", argv[i]);
00159 return (1);
00160 }
00161 }
00162 }
00163
00164 for (i = 0; i < C_FILENBR; i ++) {
00165 if ((C_fileTab[i].name[0] != '-') ||
00166 (C_fileTab[i].name[1] != '\0')) {
00167 if ((C_fileTab[i].pntr = fopen (C_fileTab[i].name, C_fileTab[i].mode)) == NULL) {
00168 errorPrint ("main: cannot open file (%d)", i);
00169 return (1);
00170 }
00171 }
00172 }
00173
00174 atomsListInit (&listdat);
00175 atomsGraphInit (&grafdat);
00176 atomsGraphInit (&grasdat);
00177 atomsGraphInit (&grandat);
00178
00179 if (atomsLoadQCPP (&listdat, &grafdat, C_filepntratsinp) != 0) {
00180 errorPrint ("main: cannot read atoms file");
00181 return (1);
00182 }
00183 FILE *atoms1 ;
00184 atoms1 = fopen("atomsListKimika", "w");
00185 atomsListSave(&listdat, 0, atoms1);
00186 fclose(atoms1) ;
00187 atoms1 = fopen("atomsGraphDatKimika", "w");
00188 atomsGraphSave(&grafdat, 0, atoms1);
00189 fclose(atoms1) ;
00190
00191 if (flag & C_FLAGSRCOUT)
00192 atomsGraphSave (&grafdat, 0, C_filepntrsrcout);
00193
00194 if (flag & C_FLAGGEOOUT)
00195 atomsListSave (&listdat, 0, C_filepntrgeoout);
00196
00197
00198
00199 dsovval = d[1];
00200 dscuval = d[2];
00201 dsnbval = MAX (dsovval, dscuval);
00202 atomsChainNeighbor (&listdat, &grandat, 1, ATOMSEDGETYPENGHB, (FLOAT) (dsnbval * dsnbval),
00203 &grafdat, 0) ;
00204
00205 atoms1 = fopen("atomsGraphKimika", "w");
00206 atomsGraphSave(&grandat, 0, atoms1);
00207 fclose(atoms1) ;
00208
00209 if (flag & C_FLAGNGBOUT)
00210 atomsGraphSave (&grandat, 0, C_filepntrngbout);
00211
00212 if ((parttab = (INT *) memAlloc (listdat.atomnbr * sizeof (INT))) == NULL) {
00213 errorPrint ("main: out of memory (1)");
00214 return (1);
00215 }
00216
00217 partnbr = (INT) d[0];
00218
00219 if (memAllocGroup ((void **)
00220 &parttab, (size_t) (listdat.atomnbr * sizeof (INT)),
00221 &velotab, (size_t) (listdat.atomnbr * sizeof (INT)), NULL) == NULL) {
00222 errorPrint ("main: out of memory (2)");
00223 return (1);
00224 }
00225
00226 for (atomnum = 0; atomnum < listdat.atomnbr; ++atomnum )
00227 velotab[atomnum] = (listdat.atomtab[atomnum].typeval == 'H') ? 1 : 4;
00228
00229
00230 atomsPartScotch (&listdat, &grandat, velotab, partnbr, parttab);
00231
00232 printf(">> parttab CONTENT: \n" );
00233 for (i = 0; i < listdat.atomnbr; ++i) {
00234 printf("(%ld , %ld ) \n",i,parttab[i]) ;
00235 }
00236 printf(" <<\n");
00237
00238 for (atomnum = grafdat.baseval; atomnum < grafdat.vertnnd; ++atomnum) {
00239 INT edgenum;
00240
00241 for (edgenum = grafdat.verttax[atomnum];
00242 edgenum < grafdat.vendtax[atomnum]; edgenum ++) {
00243 if ((grafdat.etyptax[edgenum] & ATOMSEDGETYPESTRG) != 0) {
00244 INT atomend;
00245
00246 atomend = grafdat.edgetax[edgenum];
00247 if (atomend < atomnum)
00248 continue;
00249
00250 if (parttab[atomnum - grafdat.baseval] != parttab[atomend - grafdat.baseval]) {
00251 fprintf (stderr, "Strong edge cut between vertices %ld and %ld\n",
00252 (long) atomnum, (long) atomend);
00253 }
00254 }
00255 }
00256 }
00257
00258 switch (pfmt) {
00259 case C_PFMTSCOTCH :
00260 fprintf (C_filepntrprtout, "%ld\n", (long) listdat.atomnbr);
00261 for (atomnum = 0; atomnum < listdat.atomnbr; atomnum ++) {
00262 fprintf (C_filepntrprtout, "%ld\t%ld\n",
00263 (long) atomnum, (long) parttab[atomnum]);
00264 }
00265 break;
00266 case C_PFMTQC :
00267 atomsPartInit (&partdat);
00268 atomsPartBuild (&listdat, &grandat, partnbr, parttab, &partdat, (FLOAT) (dsovval * dsovval), (FLOAT) (dscuval * dscuval));
00269 if (atomsPartCheck (&partdat) != 0) {
00270 errorPrint ("main: invalid partition");
00271 return (1);
00272 }
00273 #if 0
00274 atomsPartView (&partdat, stdout);
00275 #endif
00276 atomsPartSaveQc (&partdat, &listdat, dsovval, dscuval, C_filepntrprtout);
00277 atomsPartExit (&partdat);
00278 break;
00279 case C_PFMTQCI :
00280 atomsPartSaveQci (&listdat, &grafdat, partnbr, parttab, C_filepntrprtout);
00281 break;
00282 default :
00283 errorPrint ("main: invalid output format type");
00284 return (1);
00285 }
00286
00287 memFree (parttab);
00288
00289 exit (0);
00290 }