File: test_antechamber.py

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (101 lines) | stat: -rw-r--r-- 4,626 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'''Unit tests for the Antechamber submodule.'''

import unittest
import os, sys

from ost.mol import mm

class TestAntechamber(unittest.TestCase):
    ###########################################################################
    # HELPERS
    def _CompareInteractions(self, int_new, int_ref):
        self.assertEqual(int_new.IsParametrized(), int_ref.IsParametrized())
        if int_new.IsParametrized():
            self.assertEqual(int_new.GetNames(), int_ref.GetNames())
            self.assertEqual(int_new.GetTypes(), int_ref.GetTypes())
            self.assertEqual(int_new.GetFuncType(), int_ref.GetFuncType())
            params_new = int_new.GetParam()
            params_ref = int_ref.GetParam()
            self.assertEqual(len(params_new), len(params_ref))
            for p_new, p_ref in zip(params_new, params_ref):
                self.assertAlmostEqual(p_new, p_ref)

    def _CompareInteractionLists(self, int_list_new, int_list_ref):
        self.assertEqual(len(int_list_new), len(int_list_ref))
        for int_new, int_ref in zip(int_list_new, int_list_ref):
            self._CompareInteractions(int_new, int_ref)

    def _CompareBuildingBlocks(self, ff_new, ff_ref, res_name):
        # get BuildingBlocks
        bb_new = ff_new.GetBuildingBlock(res_name)
        bb_ref = ff_ref.GetBuildingBlock(res_name)
        # get atoms and LJs
        self.assertEqual(len(bb_new.GetAtoms()), len(bb_ref.GetAtoms()))
        for aname, aname_ref in zip(bb_new.GetAtoms(), bb_ref.GetAtoms()):
            self.assertEqual(aname, aname_ref)
            atype = bb_new.GetType(aname)
            self.assertEqual(atype, bb_ref.GetType(aname))
            self.assertEqual(bb_new.GetMass(aname), bb_ref.GetMass(aname))
            self.assertEqual(ff_new.GetMass(atype), ff_ref.GetMass(atype))
            self.assertEqual(bb_new.GetCharge(aname), bb_ref.GetCharge(aname))
            self._CompareInteractions(ff_new.GetLJ(atype), ff_ref.GetLJ(atype))
        # compare all types of interactions
        self._CompareInteractionLists(bb_new.GetBonds(), bb_ref.GetBonds())
        self._CompareInteractionLists(bb_new.GetAngles(), bb_ref.GetAngles())
        self._CompareInteractionLists(bb_new.GetDihedrals(),
                                      bb_ref.GetDihedrals())
        self._CompareInteractionLists(bb_new.GetImpropers(),
                                      bb_ref.GetImpropers())
        # those below are expected to be 0 btw
        self._CompareInteractionLists(bb_new.GetCMaps(), bb_ref.GetCMaps())
        self._CompareInteractionLists(bb_new.GetConstraints(),
                                      bb_ref.GetConstraints())
        self._CompareInteractionLists(bb_new.GetExclusions(),
                                      bb_ref.GetExclusions())
    ###########################################################################

    def testParseFromFiles(self):
        # get new ff and compare with ref.
        ff_ref = mm.Forcefield.Load('TYR/ff_AA.dat')
        # self check
        self._CompareBuildingBlocks(ff_ref, ff_ref, 'TYR')
        # check parsed files
        ff = mm.Forcefield()
        mm.antechamber.AddFromFiles(ff, 'TYR/frcmod', 'TYR/out.mpdb')
        self._CompareBuildingBlocks(ff, ff_ref, 'TYR')

    def testParseFromPath(self):
        # check parsed path
        ff = mm.Forcefield()
        mm.antechamber.AddFromPath(ff, 'TYR')
        ff_ref = mm.Forcefield.Load('TYR/ff_AA.dat')
        self._CompareBuildingBlocks(ff, ff_ref, 'TYR')

    def testAddIon(self):
        # add pseudo iron and see
        ff = mm.Forcefield()
        mm.antechamber.AddIon(ff, 'FE2', 'FE', 55, 2, 1, 0)
        bb = ff.GetBuildingBlock('FE2')
        # check block
        self.assertEqual(bb.GetAtoms(), ['FE'])
        self.assertEqual(bb.GetTypes(), ['FE'])
        self.assertEqual(bb.GetMasses(), [55])
        self.assertEqual(bb.GetCharges(), [2])
        # nothing else...
        self.assertEqual(len(bb.GetAngles()), 0)
        self.assertEqual(len(bb.GetCMaps()), 0)
        self.assertEqual(len(bb.GetConstraints()), 0)
        self.assertEqual(len(bb.GetImpropers()), 0)
        self.assertEqual(len(bb.GetDihedrals()), 0)
        self.assertEqual(len(bb.GetBonds()), 0)
        self.assertEqual(len(bb.GetExclusions()), 0)
        # check force field
        lj = ff.GetLJ('FE')
        self.assertTrue(lj.IsParametrized())
        self.assertEqual(lj.GetTypes(), ['FE'])
        self.assertEqual(lj.GetFuncType(), mm.FuncType.LJ)
        self.assertEqual(lj.GetParam(), [1, 0])

if __name__ == "__main__":
    from ost import testutils
    testutils.RunTests()