-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move unittest check to GitHub Actions Tests are parallelized * Delete tests.yml * Update setup.py * Create test_requirements.txt * Update unittest.yml * Update unittest.yml * Update README.md * Delete install_dependencies.sh * Delete install_dependencies_python2.sh * Update unittest.yml * split * split * fix * fix * -v * more * more * fix * fix * flake8 * transform * reduce testBenzeneMD * version * reduce number of epoches * further reduce time * Update docs.yml
- Loading branch information
Showing
9 changed files
with
135 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import random | ||
import unittest | ||
import torch | ||
import torchani | ||
|
||
tolerance = 1e-5 | ||
|
||
|
||
class _TestAEVBase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
ani1x = torchani.models.ANI1x() | ||
self.aev_computer = ani1x.aev_computer | ||
self.radial_length = self.aev_computer.radial_length | ||
self.debug = False | ||
|
||
def transform(self, x): | ||
return x | ||
|
||
def random_skip(self, prob=0): | ||
return random.random() < prob | ||
|
||
def assertAEVEqual(self, expected_radial, expected_angular, aev, tolerance=tolerance): | ||
radial = aev[..., :self.radial_length] | ||
angular = aev[..., self.radial_length:] | ||
radial_diff = expected_radial - radial | ||
if self.debug: | ||
aid = 1 | ||
print(torch.stack([expected_radial[0, aid, :], radial[0, aid, :], radial_diff.abs()[0, aid, :]], dim=1)) | ||
radial_max_error = torch.max(torch.abs(radial_diff)).item() | ||
angular_diff = expected_angular - angular | ||
angular_max_error = torch.max(torch.abs(angular_diff)).item() | ||
self.assertLess(radial_max_error, tolerance) | ||
self.assertLess(angular_max_error, tolerance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import torch | ||
import pickle | ||
import torchani | ||
import unittest | ||
from common_aev_test import _TestAEVBase | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
class TestAEVBenzeneMD(_TestAEVBase): | ||
|
||
def testBenzeneMD(self): | ||
for i in [2, 8]: | ||
datafile = os.path.join(path, 'test_data/benzene-md/{}.dat'.format(i)) | ||
with open(datafile, 'rb') as f: | ||
coordinates, species, expected_radial, expected_angular, _, _, cell, pbc \ | ||
= pickle.load(f) | ||
coordinates = torch.from_numpy(coordinates).float().unsqueeze(0) | ||
species = torch.from_numpy(species).unsqueeze(0) | ||
expected_radial = torch.from_numpy(expected_radial).float().unsqueeze(0) | ||
expected_angular = torch.from_numpy(expected_angular).float().unsqueeze(0) | ||
cell = torch.from_numpy(cell).float() | ||
pbc = torch.from_numpy(pbc) | ||
coordinates = torchani.utils.map2central(cell, coordinates, pbc) | ||
coordinates = self.transform(coordinates) | ||
species = self.transform(species) | ||
expected_radial = self.transform(expected_radial) | ||
expected_angular = self.transform(expected_angular) | ||
_, aev = self.aev_computer((species, coordinates), cell=cell, pbc=pbc) | ||
self.assertAEVEqual(expected_radial, expected_angular, aev, 5e-5) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import torch | ||
import pickle | ||
import unittest | ||
from common_aev_test import _TestAEVBase | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
class TestAEVNIST(_TestAEVBase): | ||
|
||
def testNIST(self): | ||
datafile = os.path.join(path, 'test_data/NIST/all') | ||
with open(datafile, 'rb') as f: | ||
data = pickle.load(f) | ||
for coordinates, species, radial, angular, _, _ in data: | ||
if self.random_skip(): | ||
continue | ||
coordinates = torch.from_numpy(coordinates).to(torch.float) | ||
species = torch.from_numpy(species) | ||
radial = torch.from_numpy(radial).to(torch.float) | ||
angular = torch.from_numpy(angular).to(torch.float) | ||
_, aev = self.aev_computer((species, coordinates)) | ||
self.assertAEVEqual(radial, angular, aev) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import torch | ||
import pickle | ||
import unittest | ||
from common_aev_test import _TestAEVBase | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
class TestAEVTripeptideMD(_TestAEVBase): | ||
|
||
def testTripeptideMD(self): | ||
tol = 5e-6 | ||
for i in range(100): | ||
datafile = os.path.join(path, 'test_data/tripeptide-md/{}.dat'.format(i)) | ||
with open(datafile, 'rb') as f: | ||
coordinates, species, expected_radial, expected_angular, _, _, _, _ \ | ||
= pickle.load(f) | ||
coordinates = torch.from_numpy(coordinates).float().unsqueeze(0) | ||
species = torch.from_numpy(species).unsqueeze(0) | ||
expected_radial = torch.from_numpy(expected_radial).float().unsqueeze(0) | ||
expected_angular = torch.from_numpy(expected_angular).float().unsqueeze(0) | ||
coordinates = self.transform(coordinates) | ||
species = self.transform(species) | ||
expected_radial = self.transform(expected_radial) | ||
expected_angular = self.transform(expected_angular) | ||
_, aev = self.aev_computer((species, coordinates)) | ||
self.assertAEVEqual(expected_radial, expected_angular, aev, tol) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.