HelloArgon.cpp 1.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "OpenMM.h"
#include <cstdio>

using namespace OpenMM;

void writePdb(const OpenMMContext& context) {
    const State state = context.getState(State::Positions);
    const std::vector<Vec3>& pos = state.getPositions();
    static int modelFrameNumber = 0; // numbering for MODEL records in pdb output
    // write out in PDB format
    modelFrameNumber++;
    printf("MODEL     %d\n", modelFrameNumber);
    for (int a = 0; a < context.getSystem().getNumParticles(); ++a)
        printf("ATOM  %5d AR    AR     1    %8.3f%8.3f%8.3f  1.00  0.00          AR\n",
            a+1, pos[a][0]*10, pos[a][1]*10, pos[a][2]*10);
    printf("ENDMDL\n");
}

int main() {
    Platform::loadPluginsFromDirectory(Platform::getDefaultPluginsDirectory());
    System system;
Michael Sherman's avatar
Michael Sherman committed
22
    NonbondedForce* nonbond = new NonbondedForce(); 
23
24
25
    system.addForce(nonbond);

    // Create atoms
Michael Sherman's avatar
Michael Sherman committed
26
    int numAtoms = 3;
27
28
29
30
31
32
    for (int a = 0; a < numAtoms; ++a) {
        system.addParticle(39.95); // mass
        nonbond->addParticle(0.0, 0.3350, 0.001603); // charge, diameter, well depth
    }

    // Large step size may be required for stability with small forces
Michael Sherman's avatar
Michael Sherman committed
33
    VerletIntegrator integrator(0.020); // step size in picoseconds
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    // Let OpenMM Context choose best platform.
    OpenMMContext context(system, integrator);
    printf( "REMARK  Using OpenMM platform %s\n", context.getPlatform().getName().c_str() );

    // Set the starting positions in the OpenMM context. Velocities will be zero.
    std::vector<Vec3> positions(numAtoms);
    for (int a = 0; a < numAtoms; ++a)
        positions[a] = Vec3(0.5*a,0,0);
    context.setPositions(positions);

    while(context.getTime() < 500.0) { // picoseconds
        writePdb(context);
        integrator.step(100); // number of steps between reports
    }
    writePdb(context);

    return 0;
}