Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torchani
Commits
83248cf1
Unverified
Commit
83248cf1
authored
Aug 31, 2018
by
Gao, Xiang
Committed by
GitHub
Aug 31, 2018
Browse files
command line tool to precompute aevs (#83)
parent
a9a792a2
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
88 additions
and
35 deletions
+88
-35
codefresh.yml
codefresh.yml
+1
-0
docs/index.rst
docs/index.rst
+1
-1
examples/inference-benchmark.py
examples/inference-benchmark.py
+5
-5
examples/model.py
examples/model.py
+4
-4
examples/neurochem-test.py
examples/neurochem-test.py
+4
-4
tests/test_aev.py
tests/test_aev.py
+2
-2
tests/test_data.py
tests/test_data.py
+2
-2
tests/test_energies.py
tests/test_energies.py
+4
-4
tests/test_ensemble.py
tests/test_ensemble.py
+3
-3
tests/test_forces.py
tests/test_forces.py
+3
-3
tests/test_ignite.py
tests/test_ignite.py
+5
-5
torchani/data/__init__.py
torchani/data/__init__.py
+1
-1
torchani/data/_pyanitools.py
torchani/data/_pyanitools.py
+0
-0
torchani/data/cache-aev.py
torchani/data/cache-aev.py
+52
-0
torchani/neurochem/__init__.py
torchani/neurochem/__init__.py
+1
-1
No files found.
codefresh.yml
View file @
83248cf1
...
...
@@ -33,6 +33,7 @@ steps:
-
python examples/neurochem-test.py ./dataset/ani_gdb_s01.h5
-
python examples/inference-benchmark.py examples/xyz_files/CH4-5.xyz
-
python -m torchani.neurochem.trainer tests/test_data/inputtrain.ipt dataset/ani_gdb_s01.h5 dataset/ani_gdb_s01.h5
-
python -m torchani.data.cache-aev tmp dataset/ani_gdb_s01.h5
256
Docs
:
image
:
'
${{BuildTorchANI}}'
...
...
docs/index.rst
View file @
83248cf1
...
...
@@ -38,7 +38,7 @@ NeuroChem Utils
.. autofunction:: torchani.neurochem.load_atomic_network
.. autofunction:: torchani.neurochem.load_model
.. autofunction:: torchani.neurochem.load_model_ensemble
.. autoclass:: torchani.neurochem.Buil
d
ins
.. autoclass:: torchani.neurochem.Buil
t
ins
.. autoclass:: torchani.neurochem.Trainer
:members:
.. automodule:: torchani.neurochem.trainer
...
...
examples/inference-benchmark.py
View file @
83248cf1
...
...
@@ -18,11 +18,11 @@ parser = parser.parse_args()
# set up benchmark
device
=
torch
.
device
(
parser
.
device
)
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
nnp
=
torch
.
nn
.
Sequential
(
buil
d
ins
.
aev_computer
,
buil
d
ins
.
models
[
0
],
buil
d
ins
.
energy_shifter
buil
t
ins
.
aev_computer
,
buil
t
ins
.
models
[
0
],
buil
t
ins
.
energy_shifter
).
to
(
device
)
...
...
@@ -54,7 +54,7 @@ class XYZ:
atom_count
-=
1
if
atom_count
==
0
:
state
=
'ready'
species
=
buil
d
ins
.
consts
.
species_to_tensor
(
species
)
\
species
=
buil
t
ins
.
consts
.
species_to_tensor
(
species
)
\
.
to
(
device
)
coordinates
=
torch
.
tensor
(
coordinates
,
device
=
device
)
self
.
mols
.
append
((
species
,
coordinates
))
...
...
examples/model.py
View file @
83248cf1
...
...
@@ -3,10 +3,10 @@ import torchani
import
os
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
consts
=
buil
d
ins
.
consts
aev_computer
=
buil
d
ins
.
aev_computer
shift_energy
=
buil
d
ins
.
energy_shifter
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
consts
=
buil
t
ins
.
consts
aev_computer
=
buil
t
ins
.
aev_computer
shift_energy
=
buil
t
ins
.
energy_shifter
def
atomic
():
...
...
examples/neurochem-test.py
View file @
83248cf1
...
...
@@ -6,7 +6,7 @@ import pickle
import
argparse
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
# parse command line arguments
parser
=
argparse
.
ArgumentParser
()
...
...
@@ -22,13 +22,13 @@ parser.add_argument('--batch_size',
default
=
1024
,
type
=
int
)
parser
.
add_argument
(
'--const_file'
,
help
=
'File storing constants'
,
default
=
buil
d
ins
.
const_file
)
default
=
buil
t
ins
.
const_file
)
parser
.
add_argument
(
'--sae_file'
,
help
=
'File storing self atomic energies'
,
default
=
buil
d
ins
.
sae_file
)
default
=
buil
t
ins
.
sae_file
)
parser
.
add_argument
(
'--network_dir'
,
help
=
'Directory or prefix of directories storing networks'
,
default
=
buil
d
ins
.
ensemble_prefix
+
'0/networks'
)
default
=
buil
t
ins
.
ensemble_prefix
+
'0/networks'
)
parser
=
parser
.
parse_args
()
# load modules and datasets
...
...
tests/test_aev.py
View file @
83248cf1
...
...
@@ -11,8 +11,8 @@ N = 97
class
TestAEV
(
unittest
.
TestCase
):
def
setUp
(
self
):
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
self
.
aev_computer
=
buil
d
ins
.
aev_computer
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
self
.
aev_computer
=
buil
t
ins
.
aev_computer
self
.
radial_length
=
self
.
aev_computer
.
radial_length
()
self
.
tolerance
=
1e-5
...
...
tests/test_data.py
View file @
83248cf1
...
...
@@ -6,8 +6,8 @@ import unittest
path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
dataset_path
=
os
.
path
.
join
(
path
,
'../dataset'
)
batch_size
=
256
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
consts
=
buil
d
ins
.
consts
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
consts
=
buil
t
ins
.
consts
class
TestData
(
unittest
.
TestCase
):
...
...
tests/test_energies.py
View file @
83248cf1
...
...
@@ -13,10 +13,10 @@ class TestEnergies(unittest.TestCase):
def
setUp
(
self
):
self
.
tolerance
=
5e-5
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
aev_computer
=
buil
d
ins
.
aev_computer
nnp
=
buil
d
ins
.
models
[
0
]
shift_energy
=
buil
d
ins
.
energy_shifter
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
aev_computer
=
buil
t
ins
.
aev_computer
nnp
=
buil
t
ins
.
models
[
0
]
shift_energy
=
buil
t
ins
.
energy_shifter
self
.
model
=
torch
.
nn
.
Sequential
(
aev_computer
,
nnp
,
shift_energy
)
def
testIsomers
(
self
):
...
...
tests/test_ensemble.py
View file @
83248cf1
...
...
@@ -15,10 +15,10 @@ class TestEnsemble(unittest.TestCase):
self
.
conformations
=
20
def
_test_molecule
(
self
,
coordinates
,
species
):
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
coordinates
=
torch
.
tensor
(
coordinates
,
requires_grad
=
True
)
aev
=
buil
d
ins
.
aev_computer
ensemble
=
buil
d
ins
.
models
aev
=
buil
t
ins
.
aev_computer
ensemble
=
buil
t
ins
.
models
models
=
[
torch
.
nn
.
Sequential
(
aev
,
m
)
for
m
in
ensemble
]
ensemble
=
torch
.
nn
.
Sequential
(
aev
,
ensemble
)
...
...
tests/test_forces.py
View file @
83248cf1
...
...
@@ -12,9 +12,9 @@ class TestForce(unittest.TestCase):
def
setUp
(
self
):
self
.
tolerance
=
1e-5
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
aev_computer
=
buil
d
ins
.
aev_computer
nnp
=
buil
d
ins
.
models
[
0
]
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
aev_computer
=
buil
t
ins
.
aev_computer
nnp
=
buil
t
ins
.
models
[
0
]
self
.
model
=
torch
.
nn
.
Sequential
(
aev_computer
,
nnp
)
def
testIsomers
(
self
):
...
...
tests/test_ignite.py
View file @
83248cf1
...
...
@@ -16,12 +16,12 @@ threshold = 1e-5
class
TestIgnite
(
unittest
.
TestCase
):
def
testIgnite
(
self
):
buil
d
ins
=
torchani
.
neurochem
.
Buil
d
ins
()
aev_computer
=
buil
d
ins
.
aev_computer
nnp
=
copy
.
deepcopy
(
buil
d
ins
.
models
[
0
])
shift_energy
=
buil
d
ins
.
energy_shifter
buil
t
ins
=
torchani
.
neurochem
.
Buil
t
ins
()
aev_computer
=
buil
t
ins
.
aev_computer
nnp
=
copy
.
deepcopy
(
buil
t
ins
.
models
[
0
])
shift_energy
=
buil
t
ins
.
energy_shifter
ds
=
torchani
.
data
.
BatchedANIDataset
(
path
,
buil
d
ins
.
consts
.
species_to_tensor
,
batchsize
,
path
,
buil
t
ins
.
consts
.
species_to_tensor
,
batchsize
,
transform
=
[
shift_energy
.
subtract_from_dataset
])
ds
=
torch
.
utils
.
data
.
Subset
(
ds
,
[
0
])
...
...
torchani/data.py
→
torchani/data
/__init__
.py
View file @
83248cf1
...
...
@@ -6,7 +6,7 @@ from os.path import join, isfile, isdir
import
os
from
._pyanitools
import
anidataloader
import
torch
from
.
import
utils
from
.
.
import
utils
def
chunk_counts
(
counts
,
split
):
...
...
torchani/_pyanitools.py
→
torchani/
data/
_pyanitools.py
View file @
83248cf1
File moved
torchani/data/cache-aev.py
0 → 100644
View file @
83248cf1
import
os
import
torch
from
..
import
aev
,
neurochem
from
.
import
BatchedANIDataset
import
pickle
if
__name__
==
'__main__'
:
import
argparse
builtin
=
neurochem
.
Builtins
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'output'
,
help
=
'Path of the output directory'
)
parser
.
add_argument
(
'dataset'
,
help
=
'Path of the dataset, can be a hdf5 file
\
or a directory containing hdf5 files'
)
parser
.
add_argument
(
'batchsize'
,
help
=
'batch size'
,
type
=
int
)
parser
.
add_argument
(
'--constfile'
,
help
=
'Path of the constant file `.params`'
,
default
=
builtin
.
const_file
)
default_device
=
'cuda'
if
torch
.
cuda
.
is_available
()
else
'cpu'
parser
.
add_argument
(
'-d'
,
'--device'
,
help
=
'Device for training'
,
default
=
default_device
)
parser
.
add_argument
(
'--no-shuffle'
,
help
=
'Whether to shuffle dataset'
,
dest
=
'shuffle'
,
action
=
'store_false'
)
parser
.
add_argument
(
'--no-tqdm'
,
dest
=
'tqdm'
,
action
=
'store_false'
,
help
=
'Whether to use tqdm to display progress'
)
parser
=
parser
.
parse_args
()
# if output directory does not exist, then create it
if
not
os
.
path
.
exists
(
parser
.
output
):
os
.
makedirs
(
parser
.
output
)
device
=
torch
.
device
(
parser
.
device
)
consts
=
neurochem
.
Constants
(
parser
.
constfile
)
aev_computer
=
aev
.
AEVComputer
(
**
consts
).
to
(
device
)
dataset
=
BatchedANIDataset
(
parser
.
dataset
,
consts
.
species_to_tensor
,
parser
.
batchsize
,
shuffle
=
parser
.
shuffle
,
properties
=
[],
device
=
device
)
if
parser
.
tqdm
:
import
tqdm
indices
=
tqdm
.
trange
(
len
(
dataset
))
else
:
indices
=
range
(
len
(
dataset
))
for
i
in
indices
:
input_
,
_
=
dataset
[
i
]
aevs
=
[
aev_computer
(
j
)
for
j
in
input_
]
aevs
=
[(
x
.
cpu
(),
y
.
cpu
())
for
x
,
y
in
aevs
]
filename
=
os
.
path
.
join
(
parser
.
output
,
'{}'
.
format
(
i
))
with
open
(
filename
,
'wb'
)
as
f
:
pickle
.
dump
(
aevs
,
f
)
torchani/neurochem/__init__.py
View file @
83248cf1
...
...
@@ -263,7 +263,7 @@ def load_model_ensemble(species, prefix, count):
return
Ensemble
(
models
)
class
Buil
d
ins
:
class
Buil
t
ins
:
"""Container for all builtin stuffs.
Attributes:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment