-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add xyz writer #46
Add xyz writer #46
Changes from all commits
178bfda
e0ae5a4
a61482d
f51bdad
3732979
e432444
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import datetime | ||
|
||
import numpy as np | ||
import unyt as u | ||
|
||
|
@@ -33,3 +35,22 @@ def read_xyz(filename): | |
raise ValueError(msg.format(n_atoms)) | ||
|
||
return top | ||
|
||
def write_xyz(top, filename): | ||
with open(filename, 'w') as out_file: | ||
out_file.write('{:d}\n'.format(top.n_sites)) | ||
out_file.write('{} {} written by topology at {}\n'.format( | ||
top.name, | ||
filename, | ||
str(datetime.datetime.now()))) | ||
for idx, site in enumerate(top.site_list): | ||
# TODO: Better handling of element guessing and site naming | ||
if site.element is not None: | ||
tmp_name = site.element.symbol | ||
else: | ||
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. What about the case when a name is >2? Wouldnt we want to support that as well? Even though its not an element anymore, i could see a case where your sites are not atomistic representations. 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. This column in XYZ files is supposed to be element. We need better element guessing, but I don't think there are good rules for handling non-elements in this format. For now I guess we can just let the entire name be stored, but it may be problematic down the line - we'll see. |
||
tmp_name = 'X' | ||
out_file.write('{0} {1:8.3f} {2:8.3f} {3:8.3f}\n'.format( | ||
tmp_name, | ||
site.position[0].in_units(u.angstrom).value, | ||
site.position[1].in_units(u.angstrom).value, | ||
site.position[2].in_units(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.
type checking?
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 would prefer doing this in a separate PR bulking up the element class