lmhale99 / atomman

Atomistic Manipulation Toolkit
Other
34 stars 40 forks source link

Add inline comments support in lammps atoms positions file #3

Closed arn-all closed 5 years ago

arn-all commented 5 years ago

Hi,

I encountered a little incompatibility reading a file saved by Ovito, and propose a workaround.

Motivations :

Atoms # atomic

1 1 0.0 0.0 2.826e-04 2 1 2.3074207 0.0 1.6315913 3 1 4.6148386 0.0 0.8157957 4 1 6.922259 0.0 0.0 5 1 9.2296772 0.0 1.6315913 ... ...



* User may want to write inline comments !
lmhale99 commented 5 years ago

Hi arn-all,

Thanks for the changes. I'll test them out soon. I was on furlough due to the Government shutdown and am trying to get caught up on where everything was before.

lmhale99 commented 5 years ago

Hi arn-all,

I merged the branches. I went through and generalized the changes you made to be more supportive of other users as well.

Let me know if something doesn't work right or for you.

arn-all commented 5 years ago

Hi lmhale99,

Thanks for reviewing my code ! It was a quick patch, your fix is definitely better !

Concerning differential displacements, I just realized that I PRed those changes by mistake -- I wanted to code a proper version before submitting to you, and would have opened a separate PR... sorry about that !

What you did works for me, but doesn't completely support the use I had in mind.

What I tried to do

When I look at the interactions between solutes and dislocations with differential displacement maps, I typically take a potential, relax a perfect crystal (no solute !) with Lammps (using the method of iprPy's relax static example), and use this relaxed system as a reference. Then, I take a simulation box with a dislocation (generated with a third-party tool), add some solute atoms wherever I want, relax it, and plot the differential displacement map of this system compared to the reference. As I added solute atoms, the number of atoms in system_0 and system_1 is different.

The error

In the new version, it causes an error when identifying in_bounds atoms : Operands could not be broadcast together with shape (135,) (137,). Fixing this, another error happens when computing dvectors_0 and dvectors_1.

I don't have other choice than comparing a system without solutes to one with solutes, as the reference state of the matrix is the pure material...

You may not want to support such specific use; in that case I'll think of a way to do it differently.

Thanks,

lmhale99 commented 5 years ago

Hi arn-all,

Run differential_displacement() using the system_0 you described and make system_1 your final relaxed system with the impurity atoms not included. That way the dd calculation is only on the matrix atoms. Since the function now returns the generated matplotlib figure, you can add the impurity atom positions to the plot after.

Maybe a separate "differential_displacement_add_atoms()" function that adds more atoms to the figure in a manner consistent to the original function would be useful?

arn-all commented 5 years ago

Hi, Yes, it's probably the easiest way... thanks for your help ! Is it possible to select/delete or copy atoms from a system in atomman, depending on a criterion (e.g. id, atype, or pos) ?

Being able to add atoms or other symbols on the plot may be useful, but it will probably just be a add_patch in most cases... As you now return the matplotlib fig, it shouldn't be too hard for the user to do such tweaks.

By the way, you may want to update the Dislocation_analysistools notebook, as the output and arguments of differential_displacement() changed. Here are the markdown formatted lines to append in the notebook (I'm sorry I can't PR it at the moment) :

- **atom_color** : (*str or list, optional*) Matplotlib color name(s) to use to display the atoms.  If str, that color will be assigned to all atypes.  If list, must give a color value or None for each atype.  Default value (None) will use cmap instead. Note: atom_color and atom_cmap can be used together as long as exactly one color or cmap is given for each unique atype.
- **atom_cmap** : (*str or list, optional*) Matplotlib colormap name(s) to use to display the atoms.  Atoms will be colored based on their initial positions and scaled using zlim. If str, that cmap will be assigned to all atypes.  If list, must give a cmap value or None for each atype.  Default value (None) will use 'hsv' cmap.  Note: atom_color and atom_cmap can be used together as long as exactly one color or cmap is given for each unique atype.
- **display_final_pos** : (*bool, optional*) Flag to display positions of atoms and arrows relative to final configuration (system_1) rather than initial configuration (system_0). Note that this does not affect the atom's cmap color as the initial plotzaxis is always used.
- **return_data** : (*bool, optional*) If True, will return a dict containing the differential displacement vectors and vector positions.  Default is False.  Note: returned values are oriented relative to the plotting axes.

Returns
- **matplotlib.figure** The generated figure
- **dict** Contains differential displacement vectors and arrow plotting information. Returned if return_data is True.
lmhale99 commented 5 years ago

Hi,

Yes, it is fairly easy to create a smaller system by criterion as the Atoms class allows numpy-style indexing based on the atoms. So, atype1atoms = system.atoms[system.atoms.atype == 1] will create a new Atoms object with only the atoms with atype 1. You can then build a new System using atype1atoms and the original system's box, pbc, and symbols. I'm trying to remember if there was a good reason that I didn't add this indexing to System as well...

The main caution (especially for the dd function) is that the indices are not retained between the old and new Atoms objects as they are implicitly defined relative to the underlying numpy arrays. For example, if you select [[0,1,2,6,78]], the new atom ids will simply be [0,1,2,3,4]. Just be careful when selecting that system_0 and system_1 remain aligned:

Thanks for reminding me about the Notebooks and documentation.

arn-all commented 5 years ago

Thanks for clarifying ! That's all good for me now.

Arnall