"vscode:/vscode.git/clone" did not exist on "69151519368da58b2b9d255260206709809ee9b4"
energy_force.py 1.34 KB
Newer Older
Xiang Gao's avatar
Xiang Gao committed
1
import torch
2
import os
Xiang Gao's avatar
Xiang Gao committed
3
4
5
import torchani

device = torch.device('cpu')
6
7
8
9
path = os.path.dirname(os.path.realpath(__file__))
const_file = os.path.join(path, '../torchani/resources/ani-1x_dft_x8ens/rHCNO-5.2R_16-3.5A_a4-8.params')  # noqa: E501
sae_file = os.path.join(path, '../torchani/resources/ani-1x_dft_x8ens/sae_linfit.dat')  # noqa: E501
network_dir = os.path.join(path, '../torchani/resources/ani-1x_dft_x8ens/train')  # noqa: E501
Xiang Gao's avatar
Xiang Gao committed
10
11

aev_computer = torchani.SortedAEV(const_file=const_file, device=device)
12
13
nn = torchani.models.NeuroChemNNP(aev_computer, derivative=True,
                                  from_=network_dir, ensemble=8)
Xiang Gao's avatar
Xiang Gao committed
14
15
16
17
18
19
20
shift_energy = torchani.EnergyShifter(sae_file)

coordinates = torch.tensor([[[0.03192167,  0.00638559,  0.01301679],
                             [-0.83140486,  0.39370209, -0.26395324],
                             [-0.66518241, -0.84461308,  0.20759389],
                             [0.45554739,   0.54289633,  0.81170881],
                             [0.66091919,  -0.16799635, -0.91037834]]],
21
22
                           dtype=aev_computer.dtype,
                           device=aev_computer.device)
Xiang Gao's avatar
Xiang Gao committed
23
24
25
26
27
28
29
30
species = ['C', 'H', 'H', 'H', 'H']

energy, derivative = nn(coordinates, species)
energy = shift_energy.add_sae(energy, species)
force = -derivative

print('Energy:', energy.item())
print('Force:', force.squeeze().numpy())