Skip to content

Commit

Permalink
mdtraj mol.xyz unit (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
yueyericardo authored Nov 6, 2020
1 parent 667a282 commit f9716fd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ani/BenchmarkCudaANISymmetryFunctions.cu
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <stdio.h>
#include <time.h>

using namespace std;

Expand Down Expand Up @@ -149,7 +151,14 @@ int main(int argc, char* argv[]) {
{12.5, 3.1625, 14.1, 2.74889}
};
CudaANISymmetryFunctions ani(species.size(), 7, 5.1, 3.5, periodicBoxVectors.size() > 0, species, radialFunctions, angularFunctions, true);
clock_t start, finish;
double duration;
start = clock();
runBenchmark(ani, stoi(argv[2]), positions, species, periodicBoxVectors);
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf(" %f s\n", duration);
printf(" %f ms/it\n", duration/stoi(argv[2])*1000);
}
catch (const exception& e) {
cout << e.what() << endl;
Expand Down
2 changes: 1 addition & 1 deletion pytorch/BenchmarkTorchANISymmetryFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

mol = mdtraj.load('molecules/2iuz_ligand.mol2')
species = torch.tensor([[atom.element.atomic_number for atom in mol.top.atoms]], device=device)
positions = torch.tensor(mol.xyz, dtype=torch.float32, requires_grad=True, device=device)
positions = torch.tensor(mol.xyz * 10, dtype=torch.float32, requires_grad=True, device=device)

nnp = torchani.models.ANI2x(periodic_table_index=True, model_index=None).to(device)
speciesPositions = nnp.species_converter((species, positions))
Expand Down
2 changes: 1 addition & 1 deletion pytorch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ device = torch.device('cuda')
# Load a molecule
molecule = mdtraj.load('molecule.mol2')
species = torch.tensor([[atom.element.atomic_number for atom in molecule.top.atoms]], device=device)
positions = torch.tensor(molecule.xyz, dtype=torch.float32, requires_grad=True, device=device)
positions = torch.tensor(molecule.xyz * 10, dtype=torch.float32, requires_grad=True, device=device)

# Construct ANI-2x and replace its native featurizer with NNPOps implementation
nnp = torchani.models.ANI2x(periodic_table_index=True).to(device)
Expand Down
2 changes: 1 addition & 1 deletion pytorch/SymmetryFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TorchANISymmetryFunctions(torch.nn.Module):
# Load a molecule
>>> molecule = mdtraj.load('molecule.mol2')
>>> species = torch.tensor([[atom.element.atomic_number for atom in molecule.top.atoms]], device=device)
>>> positions = torch.tensor(molecule.xyz, dtype=torch.float32, requires_grad=True, device=device)
>>> positions = torch.tensor(molecule.xyz * 10, dtype=torch.float32, requires_grad=True, device=device)
# Construct ANI-2x and replace its native featurizer with NNPOps implementation
>>> nnp = torchani.models.ANI2x(periodic_table_index=True).to(device)
Expand Down
4 changes: 2 additions & 2 deletions pytorch/TestSymmetryFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_compare_with_native(deviceString, molFile):

mol = mdtraj.load(f'molecules/{molFile}_ligand.mol2')
atomicNumbers = torch.tensor([[atom.element.atomic_number for atom in mol.top.atoms]], device=device)
atomicPositions = torch.tensor(mol.xyz, dtype=torch.float32, requires_grad=True, device=device)
atomicPositions = torch.tensor(mol.xyz * 10, dtype=torch.float32, requires_grad=True, device=device)

nnp = torchani.models.ANI2x(periodic_table_index=True).to(device)
energy_ref = nnp((atomicNumbers, atomicPositions)).energies
Expand All @@ -64,7 +64,7 @@ def test_model_serialization(deviceString, molFile):

mol = mdtraj.load(f'molecules/{molFile}_ligand.mol2')
atomicNumbers = torch.tensor([[atom.element.atomic_number for atom in mol.top.atoms]], device=device)
atomicPositions = torch.tensor(mol.xyz, dtype=torch.float32, requires_grad=True, device=device)
atomicPositions = torch.tensor(mol.xyz * 10, dtype=torch.float32, requires_grad=True, device=device)

nnp_ref = torchani.models.ANI2x(periodic_table_index=True).to(device)
nnp_ref.aev_computer = TorchANISymmetryFunctions(nnp_ref.aev_computer)
Expand Down

0 comments on commit f9716fd

Please sign in to comment.