"docs/source/en/api/experimental/rl.mdx" did not exist on "98f346835ab43e642f5d7d66253b1e06065af21f"
test_forces.py 1.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
import torch
import torchani
import unittest
import os
import pickle

path = os.path.dirname(os.path.realpath(__file__))
N = 97


class TestForce(unittest.TestCase):

13
14
    def setUp(self, dtype=torchani.default_dtype,
              device=torchani.default_device):
15
16
17
        self.tolerance = 1e-5
        self.aev_computer = torchani.SortedAEV(
            dtype=dtype, device=torch.device('cpu'))
18
19
        self.nnp = torchani.models.NeuroChemNNP(
            self.aev_computer, derivative=True)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

    def _test_molecule(self, coordinates, species, forces):
        _, derivative = self.nnp(coordinates, species)
        max_diff = (forces + derivative).abs().max().item()
        self.assertLess(max_diff, self.tolerance)

    def testGDB(self):
        for i in range(N):
            datafile = os.path.join(path, 'test_data/{}'.format(i))
            with open(datafile, 'rb') as f:
                coordinates, species, _, _, _, forces = pickle.load(f)
                self._test_molecule(coordinates, species, forces)


if __name__ == '__main__':
    unittest.main()