-
Notifications
You must be signed in to change notification settings - Fork 24
/
txmin.c
64 lines (48 loc) · 2.02 KB
/
txmin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sff.h"
FILE* nabout;
// Very primitive short minimizer, to illustrate the C-api; no argument-
// checking, etc., etc.
//
// Usage: txmin <parm-file> <input-coord-file> <output-coord-file>
// output to stdout
int main( int argc, char *argv[] )
{
PARMSTRUCT_T *prm; // struct to hold info from a prmtop file
XMIN_OPT_T xo; // options for the minimizer
int natm, iter;
double *xyz, *grad, *xyz_ref;
double energy, grms;
double start_time = 0.0; // dummy, since this is minimization, not md
nabout = stdout; // change to redirect output (historical kludge)
// options for the minimizer:
xmin_opt_init( &xo ); // sets the default parameters;
xo.maxiter = 50; // non-default minimization options:
xo.grms_tol = 0.0005;
xo.ls_maxatmov = 0.15;
xo.print_level = 1;
xo.method = 2;
// read in the prmtop file and the coordinates:
prm = rdparm( argv[1] ); // reads the prmtop file
natm = prm->Natom;
xyz = malloc( 3 * natm * (sizeof(double)) );
xyz_ref = malloc( 3 * natm * (sizeof(double)) );
grad = malloc( 3 * natm * (sizeof(double)) );
getxv( argv[2], natm, start_time, xyz, grad ); // reads a restart file
getxv( argv[2], natm, start_time, xyz_ref, grad ); // reads a restart file
// setup the force field parameters, and get an initial energy:
mm_options( "ntpr=5, gb=1, kappa=0.10395, rgbmax=99., cut=99.0, wcons=0. " );
// nothing frozen; nothing constrained
int* frozen = parseMaskString( "@ZZZ", prm, xyz, 2 );
int* constrained = parseMaskString( "@ZZZ", prm, xyz, 2 );
mme_init_sff( prm, frozen, constrained, xyz_ref, NULL );
iter = -1; // historical flag to give more verbose output
energy = mme( xyz, grad, &iter );
// run the minimization:
char title[] = "minimization";
energy = xmin( mme, &natm, xyz, grad, &energy, &grms, &xo );
putxv( argv[3], title, natm, start_time, xyz, xyz );
energy = mme( xyz, grad, &iter );
}