~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/bin/optking/opt.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*** OPT.CC Rollin King, begun 1999 ***/
2
 
 
3
 
/*
 
1
/*! \file
 
2
    \ingroup OPTKING
 
3
    \brief main optking function
 
4
    OPT.CC Rollin King, begun 1999 
4
5
command-line      internal specifier   what it does
5
6
--opt_step         MODE_OPT_STEP        take an ordinary geometry optimization step
6
7
--disp_nosymm      MODE_DISP_NOSYMM     displaces along all internals, assumes no sym
17
18
--reset_prefix     MODE_RESET_PREFIX    only reset the prefix of PSIF
18
19
--disp_num_plus    MODE_DISP_NUM_PLUS   only increment the current displacement number PSIF
19
20
--delete_binaries  MODE_DELETE_BINARIES just delete binary files
 
21
--test_B           MODE_TEST_BMAT       build B matrix and test numerically
20
22
--points           optinfo.points       save the energy in chkpt to PSIF list
21
23
--disp_num         optinfo.disp_num     displacement index (by default read from PSIF)
22
24
--irrep            optinfo.irrep       the irrep (1,2,...) being displaced or computed
29
31
--grad_dat         optinfo.grad_dat   read gradients from file11.dat 
30
32
*/
31
33
 
32
 
#if HAVE_CMATH
33
 
# include <cmath>
34
 
#else
35
 
# include <math.h>
36
 
#endif
37
 
 
38
 
extern "C" {
39
 
  #include <stdio.h>
40
 
  #include <libchkpt/chkpt.h>
41
 
  #include <stdlib.h>
42
 
  #include <string.h>
43
 
  #include <ctype.h>
44
 
  #include <libciomr/libciomr.h>
45
 
  #include <libipv1/ip_lib.h>
46
 
  #include <physconst.h>
47
 
  #include <libpsio/psio.h>
48
 
  #include <libqt/qt.h>   
49
 
  #include <psifiles.h>
50
 
  #include <ccfiles.h>
51
 
}
 
34
#include <cmath>
 
35
#include <cstdio>
 
36
#include <libchkpt/chkpt.h>
 
37
#include <cstdlib>
 
38
#include <cstring>
 
39
#include <cctype>
 
40
#include <libciomr/libciomr.h>
 
41
#include <libipv1/ip_lib.h>
 
42
#include <physconst.h>
 
43
#include <libpsio/psio.h>
 
44
#include <libqt/qt.h>     
 
45
#include <psifiles.h>
 
46
#include <ccfiles.h>
52
47
 
53
48
#include "opt.h"
54
49
#include "cartesians.h"
56
51
#include "salc.h"
57
52
#include "bond_lengths.h"
58
53
 
 
54
namespace psi { namespace optking {
 
55
 
59
56
void intro(int argc, char **argv);
60
57
void free_info(int nsimples);
61
58
int *count_internals(cartesians &cart_geom, int intco_given);
62
 
extern "C" void zmat_to_intco(void);
63
 
extern "C" void get_optinfo();
 
59
extern void zmat_to_intco(void);
 
60
extern void get_optinfo();
64
61
extern void get_syminfo(internals &simples);
65
62
extern void delocalize(internals &simples, cartesians &carts);
66
63
extern void disp_user(cartesians &carts, internals &simples, 
79
76
extern void grad_save(cartesians &carts);
80
77
extern void energy_save(cartesians &carts);
81
78
extern int opt_step(cartesians &carts, internals &simples, salc_set &symm_salcs);
 
79
extern int opt_step_cart(cartesians &carts, internals &simples, salc_set &symm_salcs);
82
80
extern int *read_constraints(internals &simples);
83
81
 
84
82
extern int disp_freq_grad_cart(cartesians &carts);
85
83
extern void freq_grad_cart(cartesians &carts);
86
84
extern int disp_freq_energy_cart(cartesians &carts);
87
85
extern void freq_energy_cart(cartesians &carts);
 
86
int test_B(cartesians &carts, internals &simples, salc_set &symm);
88
87
 
89
88
void chkpt_restart(char *new_prefix);
90
89
 
 
90
}} // namespace psi::optking
 
91
 
 
92
extern "C" { const char *gprgid() { const char *prgid = "OPTKING"; return(prgid); } }
 
93
 
 
94
using namespace psi::optking;
 
95
 
91
96
int main(int argc, char **argv) {
92
97
 
93
98
    int i,j,a,b,dim,count,dim_carts,user_intcos, *constraints,xyz;
99
104
    optinfo.mode = MODE_OPT_STEP;
100
105
    optinfo.disp_num = 0;
101
106
    optinfo.points = 3;
102
 
    optinfo.points_freq = 3; // always 3 for now
 
107
    optinfo.points_freq_grad_ints = 3; // always 3 for now
103
108
    optinfo.energy_dat = 0;
104
109
    optinfo.grad_dat = 0;
105
110
    for (i=1; i<argc; ++i) {
179
184
        optinfo.mode = MODE_DELETE_BINARIES;
180
185
        parsed++;
181
186
      }
 
187
      else if (!strcmp(argv[i],"--test_B")) {
 
188
        optinfo.mode = MODE_TEST_BMAT;
 
189
        parsed++;
 
190
      }
182
191
      else if (!strcmp(argv[i],"--points")) {
183
192
        sscanf(argv[++i], "%d", &optinfo.points);
184
193
        parsed+=2;
201
210
        parsed++;
202
211
      }
203
212
      else {
204
 
        printf("command line argument not understood.\n");
205
 
        exit(1);
 
213
        //printf("command line argument not understood.\n");
 
214
        //exit(1);
 
215
                break;
206
216
      }
207
217
    }
208
218
 
209
 
    psi_start(argc-parsed,argv+parsed,0);
 
219
    psi_start(&infile,&outfile,&psi_file_prefix,argc-parsed,argv+parsed,0);
210
220
    /* init_in_out() sets the value of "infile", so we need to save it */
211
221
    fp_input = infile;
212
222
    
218
228
    optinfo.simples_present = 0;
219
229
    optinfo.salcs_present = 0;
220
230
    ffile_noexit(&fp_intco, "intco.dat", 2);
221
 
    if (fp_intco != NULL) {
 
231
    if (fp_intco != NULL)
222
232
      ip_append(fp_intco, outfile) ;
223
 
      if ( ip_exist(":INTCO",0) ) {
224
 
        ip_cwk_add(":INTCO");
225
 
        optinfo.simples_present = 1;
226
 
      }
227
 
      if ( ip_exist("SYMM",0) || ip_exist("ASYMM",0) )
228
 
        optinfo.salcs_present = 1;
 
233
    if ( ip_exist(":INTCO",0) ) {
 
234
      ip_cwk_add(":INTCO");
 
235
      optinfo.simples_present = 1;
 
236
    }
 
237
    if ( ip_exist("SYMM",0) || ip_exist("ASYMM",0) )
 
238
      optinfo.salcs_present = 1;
 
239
    if (fp_intco != NULL)
229
240
      fclose(fp_intco);
230
 
    }
231
 
    //printf("simples_present already? %d\n",optinfo.simples_present);
232
 
    //printf("salcs_present already? %d\n",optinfo.salcs_present);
233
241
 
234
 
    psio_init();
 
242
    psio_init(); psio_ipv1_config();
235
243
    get_optinfo();
236
244
 
237
245
    // generate simples from zmat
256
264
           && (optinfo.mode != MODE_RESET_PREFIX) && (optinfo.mode != MODE_DISP_NUM_PLUS)
257
265
           && (optinfo.mode != MODE_DELETE_BINARIES) ) {
258
266
      fprintf(outfile,
259
 
      "\nCartesian geometry and possibly gradient in a.u. with masses\n");
 
267
      "\nCartesian geometry in a.u. with masses\n");
260
268
      carts.print(2,outfile,0,disp_label,0);
261
269
    }
262
270
    delete [] disp_label;
273
281
    coord = carts.get_coord();
274
282
    simples.compute_internals(carts.get_natom(), coord);
275
283
    simples.compute_s(carts.get_natom(), coord);
276
 
    // simples.print_s();
 
284
//simples.print_s();
277
285
    free(coord);
278
286
    if ( (optinfo.mode != MODE_DISP_LOAD) && (optinfo.mode != MODE_LOAD_REF)
279
287
      && (optinfo.mode != MODE_RESET_PREFIX) && (optinfo.mode != MODE_DISP_NUM_PLUS)
292
300
    if (!(optinfo.salcs_present)) {
293
301
      if (optinfo.delocalize) {
294
302
        fprintf(outfile,"\nForming delocalized internal coordinates.\n");
295
 
        // delocalize(carts.get_natom(),simples);
296
303
        delocalize(simples, carts);
297
304
      }
298
305
      else {
347
354
      salc_set symm_salcs("SYMM");
348
355
      if (!optinfo.redundant)
349
356
        symm_salcs.print();
350
 
      a = opt_step(carts, simples, symm_salcs);
 
357
      if (optinfo.test_B) {
 
358
        test_B(carts,simples,symm_salcs);
 
359
        coord = carts.get_coord(); // restore internals to undisplaced state
 
360
        simples.compute_internals(carts.get_natom(), coord);
 
361
        simples.compute_s(carts.get_natom(), coord);
 
362
      }
 
363
      if (optinfo.cartesian)
 
364
        a = opt_step_cart(carts, simples, symm_salcs);
 
365
      else
 
366
        a = opt_step(carts, simples, symm_salcs);
351
367
      free_info(simples.get_num());
352
368
      exit_io();
353
 
      // fprintf(stderr,"Optking returning value %d\n", a);
354
369
      return a;
355
370
    }
356
371
 
518
533
      return(0);
519
534
    }
520
535
 
 
536
    if (optinfo.mode == MODE_TEST_BMAT) {
 
537
      fprintf(outfile," \n ** Testing B matrix **\n");
 
538
      salc_set symm_salcs("SYMM");
 
539
      test_B(carts,simples,symm_salcs);
 
540
      free_info(simples.get_num());
 
541
      exit_io();
 
542
      return (0);
 
543
    }
 
544
 
521
545
    if (optinfo.mode == MODE_RESET_PREFIX) {
522
546
      /* delete CC temporary files */
523
547
      if((strcmp(optinfo.wfn, "MP2")==0)       || (strcmp(optinfo.wfn, "CCSD")==0)  ||
587
611
      close_PSIF();
588
612
    }
589
613
    return(0);
590
 
  }
 
614
}
 
615
 
 
616
namespace psi { namespace optking {
591
617
 
592
618
/***  INTRO   prints into ***/
593
619
void intro(int argc, char **argv) {
614
640
 
615
641
 // free syminfo
616
642
  free(syminfo.symmetry);
 
643
  free_int_matrix(syminfo.ct);
 
644
  free_int_matrix(syminfo.ict);
 
645
  free_int_matrix(syminfo.fict);
617
646
  for (i=0; i<syminfo.nirreps; ++i) {
618
 
    free(syminfo.ct[i]);
619
 
    free(syminfo.ict[i]);
620
 
    free(syminfo.fict[i]);
621
647
    free(syminfo.irrep_lbls[i]);
622
648
    free(syminfo.clean_irrep_lbls[i]);
623
649
  }
624
 
  free(syminfo.ct);
625
 
  free(syminfo.ict);
626
 
  free(syminfo.fict);
627
650
  free(syminfo.irrep_lbls);
628
651
  free(syminfo.clean_irrep_lbls);
629
 
 
630
 
  for (i=0; i<nsimples; ++i) {
631
 
    free(syminfo.ict_ops[i]);
632
 
    free(syminfo.ict_ops_sign[i]);
633
 
  }
634
 
  free(syminfo.ict_ops);
635
 
  free(syminfo.ict_ops_sign);
 
652
  
 
653
  free_int_matrix(syminfo.ict_ops);
 
654
  free_int_matrix(syminfo.ict_ops_sign);
636
655
 
637
656
  // free optinfo
638
657
  free(optinfo.to_dummy);
639
658
  free(optinfo.to_nodummy);
 
659
  if (optinfo.nfragment > 1) {
 
660
    free(optinfo.natom_per_fragment);
 
661
    free(optinfo.nallatom_per_fragment);
 
662
    free(optinfo.nref_per_fragment);
 
663
    free(optinfo.fragment_coeff);
 
664
  }
640
665
  return;
641
666
}
642
667
 
705
730
  chkpt_close();
706
731
  return;
707
732
}
 
733
 
 
734
}} /* namespace psi::optking */