-
Notifications
You must be signed in to change notification settings - Fork 33
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
Lammps writer #28
Lammps writer #28
Conversation
I'm guessing there's probably room to mess with smoothly handling units as things get written out. Something like
Or maybe instead of specifying |
I think for now we should stick to adding units as we go, and not making new variables. But that approach is probably how we would implement unit systems, except probably with dictionaries instead of |
In mBuild's Lammps writer, the use of Parmed's atom indexing was heavily used to keep track of atom indices for bonds, angles, and dihedrals. Currently, Either we come up with a temporary workaround or effort should rather focused on handling indexing better. |
I'm not sure which option is best, but the use of an index-site map or |
I vote an index-site map - if we added We'd have to flesh out the lammps-writing more, but doing lots of list indexing seems somewhat inefficient ("linear complexity in list length") - to that end, dictionaries are faster as just straightforward look-up tables |
This is pretty close to being able to write out a simple system of LJ particles. Once #47 gets merged, The code commented out was replaced with |
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.
beginning review with some changes
I want to review this myself and then should be read for review. |
Last change I made was |
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.
Looks good overall, just few small comments and nits. This will be a big step forward for this package.
topology/formats/lammpsdata.py
Outdated
data.write('{0:.6f} {1:.6f} zlo zhi\n'.format( | ||
zlo_bound, zhi_bound)) | ||
data.write('{0:.6f} {1:.6f} {2:.6f} xy xz yz\n'.format( | ||
xy, xz, yz)) |
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.
... in this block of code (including the above few lines),
xy, xz, yz)) | |
xy.in_units_of(u.angstrom), xz.in_units_of(u.angstrom), yz.in_units_of(u.angstrom))) |
Maybe this is a little verbose but this is my preference (which I can be talked out of).
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.
I was contemplating this Friday. I originally stripped the units earlier because adding a unyt_array
with a numpy.array
is messy, as is being done to calculate some of the bounds. However I think this is okay as long as I set the numpy arrays as unyt arrays.
I'm still not entirely sure how to best handle converting the units of box angles and lengths.
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.
I think getting x/y/lo/hi should only be math on unyt_array
objects. xlo
/xhi
/ylo
/yhi
should all come from vectors
with units, and even though it may not be pretty I think your changes are good.
I'm still not entirely sure how to best handle converting the units of box angles and lengths.
I think your changes are good; keeping things as unyt arrays until they're being written out. The only thing that would be worth considering down the line is not converting them to u.angstrom
at the beginning and writing them out as xlo_bound.in_units_of(u.angstrom).value
later on, but I think what you have now is what we want to do. What are you concerned about?
if atom_style not in ['atomic', 'charge', 'molecular', 'full']: | ||
raise ValueError('Atom style "{}" is invalid or is not currently supported'.format(atom_style)) | ||
|
||
xyz = list() |
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.
This is a a detail outside the scope of this PR (don't know how to easily add a non-review comments during a review) but we can probably initialize it to be an empty numpy array instead of appending to lists
top.update_connection_list() | ||
write_lammpsdata(top, filename='triclinic.data') | ||
|
||
#def test_num_atoms(): |
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.
This is a good idea (and it works for me locally) 👍
re: cd2290a this should be done in the unit test so we can be sure the masses are written out. So just adding >>> from topology.core.site import Site
>>> Site(name='foo', mass=1)
/Users/mwt/software/topology/topology/core/site.py:118: UserWarning: Masses are assumed to be g/mol
warnings.warn("Masses are assumed to be g/mol")
<topology.core.site.Site object at 0x106eae390>
>>> site = Site(name='foo', mass=1)
>>> site.mass
unyt_quantity(1., 'g/mol') |
Maybe, I'm misinterpreting. But I think I'm doing this currently in |
If what I'm seeing is accurate: you're doing everything but setting the mass (the default >>> from topology.core.atom_type import AtomType
>>> from topology.core.site import Site
>>> Site(name='foo').mass is None
True
>>> AtomType().mass
unyt_quantity(0., 'g/mol') Sitenote: it's pretty silly that LAMMPS doesn't play well with zero mass |
Oh I see the confusion now, I messed up that commit for some reason. |
Sweet, I can read these in now, and it looks good to me.
|
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.
- Do we need to convert xyz to the correct atom style before doing anything? Or at least ensure xyz is in Angstrom?
- I think we might need to enforce some wrapping inside the box (however the box gets defined)?
Good catch. It looks to me like they're stored as units so we shouldn't need to ensure they're a specific unit beforehand. But we'd want to make sure they're printed out in angstroms, i.e. changing this line https://github.com/mattwthompson/topology/blob/f513814ad125fed2bd88c5ca2e72f69676547b23/topology/formats/lammpsdata.py#L207 to
I don't think LAMMPS needs everything to be wrapped - I could be wrong - but I'm ok with punting on this specific issue either way. |
if forcefield: | ||
sigmas = [site.atom_type.parameters['sigma'] for site in topology.site_list] | ||
epsilons = [site.atom_type.parameters['epsilon'] for site in topology.site_list] | ||
sigma_dict = dict([(unique_types.index(atom_type)+1,sigma) for atom_type,sigma in zip(types,sigmas)]) |
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.
Oh right, units-system issues here. For atomstyle real, I think it's angstrom and kcal/mol?
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.
Okay yeah that is true, from lammps |
So is this good to merge? I understand this is very limited in the scope of what the writer will eventually be, but I think this is a good first go. |
topology/formats/lammpsdata.py
Outdated
data.write(atom_line.format( | ||
index=i+1,type_index=unique_types.index(types[i])+1, | ||
zero=0,charge=0, | ||
x=coords[0].value,y=coords[1].value,z=coords[2].value)) |
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.
x=coords[0].value,y=coords[1].value,z=coords[2].value)) | |
x=coords[0].in_units_of(u.angstrom).value, | |
y=coords[1].in_units_of(u.angstrom).value, | |
z=coords[2].in_units_of(u.angstrom).value, | |
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.
I think this is the only thing left before merging
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.
Cool, just committed that change.
Thanks for the contribution! |
Getting a Lammps writer going, mostly adapted from mBuild. Definitely a work in progress. As the
Site
class begins to take shape, I can start to expand on this.