"platforms/cpu/src/CpuCustomNonbondedForce.cpp" did not exist on "a17524632a35e22cd96deac605d2ad237f959933"
testInstallation.py 4.28 KB
Newer Older
1
from __future__ import print_function
2
from __future__ import absolute_import
3
4
5
6
import os
import sys
# First make sure OpenMM is installed.

7
8
9
10
11
12
try:
    from simtk.openmm.app import *
    from simtk.openmm import *
    from simtk.unit import *
except ImportError as err:
    simtk_import_failed = True
Robert McGibbon's avatar
Robert McGibbon committed
13
    simtk_import_error = str(err)
14
15
else:
    simtk_import_failed = False
16

17

18
def run_tests():
19
20
21
22
23
24
    """
    Runs a set of tests to determine which platforms are available and tests the
    relative accuracy between them. This can be used to determine if the Python
    API is installed and working properly, as well as the fidelity of the
    underlying OpenMM libraries with respect to computing energies and forces on
    the different platforms supported by your installation.
25

26
27
28
29
    This test prints the available platforms and the relative force errors
    between them for a test system. If a problem is detected, TestingError is
    raised.
    """
30
31
32
33
    print()
    print('OpenMM Version:', Platform.getOpenMMVersion())
    print('Git Revision:', version.git_revision)
    print()
34

35
36
37
38
39
    # Create a System for the tests.
    data_dir = os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'openmm', 'app', 'data')
    pdb = PDBFile(os.path.join(data_dir, 'test.pdb'))
    forcefield = ForceField('amber99sb.xml', 'tip3p.xml')
    system = forcefield.createSystem(pdb.topology, nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds)
Robert McGibbon's avatar
Robert McGibbon committed
40

41
    # List all installed platforms and compute forces with each one.
Robert McGibbon's avatar
Robert McGibbon committed
42

43
44
45
    numPlatforms = Platform.getNumPlatforms()
    print("There are", numPlatforms, "Platforms available:")
    print()
46
    forces = [None] * numPlatforms
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    platformErrors = {}
    for i in range(numPlatforms):
        platform = Platform.getPlatform(i)
        print(i+1, platform.getName(), end=" ")
        integrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)
        try:
            simulation = Simulation(pdb.topology, system, integrator, platform)
            simulation.context.setPositions(pdb.positions)
            forces[i] = simulation.context.getState(getForces=True).getForces()
            del simulation
            print("- Successfully computed forces")
        except:
            print("- Error computing forces with", platform.getName(), "platform")
            platformErrors[platform.getName()] = sys.exc_info()[1]
Robert McGibbon's avatar
Robert McGibbon committed
61

62
    # Give details of any errors.
Robert McGibbon's avatar
Robert McGibbon committed
63

64
65
66
    for platform in platformErrors:
        print()
        print("%s platform error: %s" % (platform, platformErrors[platform]))
Robert McGibbon's avatar
Robert McGibbon committed
67

68
    # See how well the platforms agree.
Robert McGibbon's avatar
Robert McGibbon committed
69

70
    errorsOk = True
71
72
73
74
75
76
77
78
79
80
81
82
    if numPlatforms > 1:
        print()
        print("Median difference in forces between platforms:")
        print()
        for i in range(numPlatforms):
            for j in range(i):
                if forces[i] is not None and forces[j] is not None:
                    errors = []
                    for f1, f2 in zip(forces[i], forces[j]):
                        d = f1-f2
                        error = sqrt((d[0]*d[0]+d[1]*d[1]+d[2]*d[2])/(f1[0]*f1[0]+f1[1]*f1[1]+f1[2]*f1[2]))
                        errors.append(error)
83
84
85
86
87
88
89
90
91
92
93
                    median = sorted(errors)[len(errors)//2]
                    if median < 1e-4:
                        message = ''
                    else:
                        message = '  *** LARGE DIFFERENCE **'
                        errorsOk = False
                    print("{0} vs. {1}: {2:g}{3}".format(Platform.getPlatform(j).getName(),
                                                  Platform.getPlatform(i).getName(), median, message))
    if errorsOk:
        print()
        print('All differences are within tolerance.')
94

95
96
97
98
99
100
101
102

def main():
    if simtk_import_failed:
        print('Failed to import OpenMM packages; OpenMM will not work.\n'            
              'Make sure OpenMM is installed and the library path is set correctly.'
              '\n\nError message: %s' % simtk_import_error,
              file=sys.stderr)
        sys.exit(1)
103
104
105

    try:
        run_tests()
106
107
108
109
110
111
    except Exception as err:
        print('Problem with OpenMM installation '
              'encountered. OpenMM will not work until the problem '
              'has been fixed.\n\n',
              file=sys.stderr)
        print('Error message: %s' % str(err), file=sys.stderr)
112
        sys.exit(1)
113
114
115
116


if __name__ == '__main__':
    main()