Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Cloudac7
Copy link

For some large, non-orthogonal box, it could be rather slow using direct mode to preprocess. So in this pr, a new mode ndirect, using numpy ndarray to produce neighbor list, is developed and has been tested to give the same result as the original direct mode.

Copy link
Owner

@txie-93 txie-93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! The code looks great. I have several very minor issues, mainly about formatting. The code should be ready to merge once you fix those. In addition, did you test if the new algorithm gives the exact same results as the existing two for the given trajectories?

@@ -96,7 +96,7 @@ Then, you can use the `preprocess.py` to preprocess the `traj.npz`. It will crea
python preprocess.py traj.npz graph.npz
```

Note that the graph construction is slow especially for large MD trajectories. There two different graph construction algorithms implemented. The default `--backend kdtree` has a linear scaling but only works for orthogonal simulation box. For non-orthogonal simulation, use flag `--backend direct` which has a quadratic scaling. You can also take advantage of the multiprocessing with flag `--n-workers`. For other flags, checkout the help information with `python preprocess.py -h`.
Note that the graph construction is slow especially for large MD trajectories. There two different graph construction algorithms implemented. The default `--backend kdtree` has a linear scaling but only works for orthogonal simulation box. For non-orthogonal simulation, use flag `--backend direct` or `--backend ndirect` which has a quadratic scaling (for the two choices, the latter is specially efficient for large cells, while the former could be quick for small ones). You can also take advantage of the multiprocessing with flag `--n-workers`. For other flags, checkout the help information with `python preprocess.py -h`.
Copy link
Owner

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

'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.'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ofdealing -> of dealing

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, '
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove “available” after “ndirect”

@@ -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],
Copy link
Owner

Choose a reason for hiding this comment

The 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.

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(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a for loop here. As well as several places below.

:, 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(
Copy link
Owner

@txie-93 txie-93 Oct 17, 2019

Choose a reason for hiding this comment

The 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.

@Cloudac7
Copy link
Author

Thank you for your contribution! The code looks great. I have several very minor issues, mainly about formatting. The code should be ready to merge once you fix those. In addition, did you test if the new algorithm gives the exact same results as the existing two for the given trajectories?

Thanks a lot for pointing out and I will fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants