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

Mismatch between CifParser parsed coordinates and coordinates in the CIF file #4250

Closed
JuJueTanWan opened this issue Jan 12, 2025 · 6 comments
Labels

Comments

@JuJueTanWan
Copy link

Python version

Python 3.9.21

Pymatgen version

2024.8.9

Operating system version

CentOS 7.9

Current behavior

Hello, I encountered an issue when using pymatgen's CifParser to parse a .cif file. Specifically, I noticed that the fractional coordinates of some atoms (X and Y) parsed by CifParser do not match the original fractional coordinates in the CIF file. Below are the details of my observation.

Here is the content of the c2db-2832-WSe2-_shixc2db-2696-MoS2-_shi_1.cif file I am using:
W W0 1 0.66666667 0.33333333 0.31812705 1
Se Se1 1 0.33333333 0.66666667 0.26186394 1
Se Se2 1 0.33333333 0.66666667 0.37439016 1
Mo Mo3 1 1.00000000 1.00000000 0.55060730 1
S S4 1 0.66666666 1.33333334 0.49811805 1
S S5 1 0.66666666 1.33333334 0.60309655 1

Here is the code I used to parse the CIF file:
from pymatgen.io.cif import CifParser

cif_file = "c2db-2832-WSe2-_shixc2db-2696-MoS2-_shi_1.cif "
parser = CifParser(cif_file)
structure = parser.get_structures(primitive=False)[0]

for site in structure.sites:
specie = site.specie
original_frac_coords = site._frac_coords
print(f"{specie}: {original_frac_coords}")

The output from the code is as follows:
Mo: [0.33333334 0.66666667 0.5506073 ]
W: [0.66666667 0.33333333 0.31812705]
Se: [0.33333333 0.66666667 0.26186394]
Se: [0.33333333 0.66666667 0.37439016]
S: [0. 0. 0.49811805]
S: [0. 0. 0.60309655]

The Z coordinates for all atoms are correct.
The X and Y coordinates for W and Se atoms match the values in the CIF file, but the X and Y coordinates for Mo and S atoms are incorrect:
Mo's original fractional coordinates in the CIF file are [1.00000000, 1.00000000, 0.55060730], but CifParser outputs [0.33333334, 0.66666667, 0.55060730].
S's original fractional coordinates in the CIF file are [0.66666666, 1.33333334, 0.49811805], but CifParser outputs [0.0, 0.0, 0.49811805].

Expected Behavior

Why does CifParser parse some fractional coordinates (X and Y) as values that do not match the original CIF file?
Is there a way to avoid this normalization or mapping behavior and directly retrieve the fractional coordinates as they are in the CIF file?
Any clarification or guidance on this behavior would be greatly appreciated. Thank you!

Minimal example

No response

Relevant files to reproduce this bug

No response

@DanielYang59
Copy link
Contributor

@JuJueTanWan Hi thanks for reporting this issue. While I'm happy to look into this issue, is it possible for you to provide the complete CIF file (looks like the provided is a snippet of it) for me to recreate this issue (GitHub doesn't support uploading cif files directly, but you could add a .txt extension as it's a text file anyway)?

@JuJueTanWan
Copy link
Author

Hi,

Thank you for your prompt response and for your willingness to look into this issue. I've renamed the CIF file and processing script with a .txt extension as you suggested. Please find the updated files attached.

Thanks again for your help, and I look forward to your feedback!

c2db-2832-WSe2-_shixc2db-2696-MoS2-_shi_0.txt
insert_atom_M_TM_X.txt

@JuJueTanWan
Copy link
Author

JuJueTanWan commented Jan 13, 2025 via email

@DanielYang59
Copy link
Contributor

DanielYang59 commented Jan 13, 2025

@JuJueTanWan Thanks for sending through the file and code snippet. However I cannot recreate the issue (I didn't look into the custom insert_atom_M_TM_X code but I'm not seeing any issue with the CifParser).


from pymatgen.io.cif import CifParser


cif_file = "test_cif.cif"
parser = CifParser(cif_file)
structure = parser.parse_structures(primitive=False)[0]

for site in structure.sites:
    print(f"{site.specie}: {site.frac_coords}")

I got:

Mo: [0.        0.        0.5506073]
W: [0.66666667 0.33333333 0.31812705]
Se: [0.33333333 0.66666667 0.26186394]
Se: [0.33333333 0.66666667 0.37439016]
S: [0.66666667 0.33333334 0.49811805]
S: [0.66666667 0.33333334 0.60309655]

The cif file:

  W  W0  1  0.66666667  0.33333333  0.31812705  1
  Se  Se1  1  0.33333333  0.66666667  0.26186394  1
  Se  Se2  1  0.33333333  0.66666667  0.37439016  1
  Mo  Mo3  1  1.00000000  1.00000000  0.55060730  1
  S  S4  1  0.66666666  1.33333334  0.49811805  1
  S  S5  1  0.66666666  1.33333334  0.60309655  1

@QuantumChemist
Copy link
Contributor

QuantumChemist commented Jan 13, 2025

It seems to me that the cell's space group allows for different definitions/orientations in space, and therefore, the parser changes the coordinates. The cells might be equal, just facing another direction.

@shyuep
Copy link
Member

shyuep commented Jan 17, 2025

By default, CifParser performs a primitive cell reduction since this is generally desired for calculations. If you prefer not to, you can always specify primitive=False as an arg to get_structures. Otherwise, users generally should use Structure.from_file, which works more in the way that the data is returned unmodified.

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

No branches or pull requests

4 participants