-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new "ndirect" mode for preprocessing #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,12 @@ | |
prep_parser.add_argument('--radius', type=float, default=7., | ||
help='search radius for finding nearest neighbors ' | ||
'(default: 7.)') | ||
prep_parser.add_argument('--backend', choices=['kdtree', 'direct'], | ||
default='kdtree', help='either "kdtree" or "direct", ' | ||
prep_parser.add_argument('--backend', choices=['kdtree', 'direct', 'ndirect'], | ||
default='kdtree', help='"kdtree", "direct" or "ndirect" available, ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove “available” after “ndirect” |
||
'the backend used to search for nearest neighbors. ' | ||
'"kdtree" has linear scaling but only works for ' | ||
'orthogonal lattices. "direct" works for trigonal ' | ||
'lattices but has quadratic scaling. ' | ||
'lattices but has quadratic scaling. "ndirect" is ' | ||
'an enhanced method for "direct" which could ' | ||
'accelarate the process ofdealing with large lattices.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ofdealing -> of dealing |
||
'(default: "kdtree")') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import numpy as np | ||
from .utils import PeriodicCKDTree, distance_pbc | ||
from tqdm import tqdm | ||
from pymatgen.core.structure import IStructure | ||
from pymatgen.core.structure import IStructure, Structure | ||
|
||
|
||
class Preprocess(object): | ||
|
@@ -72,8 +72,8 @@ def __init__(self, input_file, output_file, n_nbrs=20, radius=7., | |
self.output_file = output_file | ||
self.n_nbrs = n_nbrs | ||
self.radius = radius | ||
if backend not in ['kdtree', 'direct']: | ||
raise ValueError('backend should be either "kdtree" or "direct", ' | ||
if backend not in ['kdtree', 'direct', 'ndirect']: | ||
raise ValueError('backend should be "kdtree", "ndirect" or "direct", ' | ||
'but got {}'.format(backend)) | ||
self.backend = backend | ||
self.verbose = verbose | ||
|
@@ -169,6 +169,33 @@ def construct_graph(self, traj_coords, lattices, atom_types, target_index): | |
'target_index': target_index, | ||
'nbr_lists': nbr_lists, | ||
'nbr_dists': nbr_dists} | ||
elif self.backend == 'ndirect': | ||
stcs = [Structure(lattice=lattices[i], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t use such complex list comprehensions. Use a for loop for code readability. |
||
species=atom_types, | ||
coords=traj_coords[i], | ||
coords_are_cartesian=True) | ||
for i in tqdm(range(len(traj_coords)), | ||
desc='Generating structure...', disable=not self.verbose)] | ||
a, b, c = [np.ceil(2*self.radius/d).astype('int') | ||
for d in stcs[0].lattice.abc] | ||
if [a, b, c] != [1, 1, 1]: | ||
_ = [stc.make_supercell( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a for loop here. As well as several places below. |
||
[np.ceil(2*self.radius/d).astype('int') for d in stc.lattice.abc]) | ||
for stc in tqdm(stcs, desc='Building supercell...', disable=not self.verbose)] | ||
nbr_lists = np.array([stc.distance_matrix.argsort()[ | ||
:, 1:1+self.n_nbrs] for stc in tqdm( | ||
stcs, desc='Generating neighbor index...', disable=not self.verbose)], dtype='int32') | ||
nbr_dists = np.array([np.sort(stc.distance_matrix)[ | ||
:, 1:1+self.n_nbrs] for stc in tqdm( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you reformat your code according to PEP8? There should be whitespaces between 1+ for example. You can do it with automated tools. |
||
stcs, desc='Generating neighbor distance...', disable=not self.verbose)], dtype='float32') | ||
nbr_lists, nbr_dists = np.stack(nbr_lists), np.stack(nbr_dists) | ||
if not np.all((nbr_dists < self.radius) & (nbr_dists > 0)): | ||
raise('not find enough neighbors') | ||
return {'traj_coords': traj_coords, | ||
'atom_types': atom_types, | ||
'target_index': target_index, | ||
'nbr_lists': nbr_lists, | ||
'nbr_dists': nbr_dists} | ||
|
||
def preprocess(self): | ||
if self.verbose: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typos:
Two different graph convolution algorithm -> three