-
Notifications
You must be signed in to change notification settings - Fork 884
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
Comments
@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 |
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 |
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!
xudonghuichem97
***@***.***
---- Replied Message ----
FromHaoyu (Daniel) ***@***.***>Date1/13/2025 ***@***.***>***@***.***>,
***@***.***>SubjectRe: [materialsproject/pymatgen] Mismatch between CifParser parsed coordinates and coordinates in the CIF file (Issue #4250)
@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)?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
# generated using pymatgen
data_MoW(SeS)2
_symmetry_space_group_name_H-M 'P 1'
_cell_length_a 3.33061866
_cell_length_b 3.33061866
_cell_length_c 29.90433353
_cell_angle_alpha 90.00000000
_cell_angle_beta 90.00000000
_cell_angle_gamma 120.00000000
_symmetry_Int_Tables_number 1
_chemical_formula_structural MoW(SeS)2
_chemical_formula_sum 'Mo1 W1 Se2 S2'
_cell_volume 287.28607864
_cell_formula_units_Z 1
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
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
#!/usr/bin/env python3
import os
import shutil
import warnings
from pymatgen.io.vasp import Poscar
from pymatgen.io.cif import CifParser, CifWriter
from pymatgen.core.structure import Structure
warnings.filterwarnings("ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category=UserWarning)
def insert_atom_M_TM_X(cif_file, atom_type, output_file, suppress_warnings=True):
"""
The file's comments are the same as insert_atom_X_TM_V.py,
which you can refer to if necessary!
"""
parser = CifParser(cif_file)
structure = parser.parse_structures(primitive=True)[0]
sulfur_atoms = []
metal_atoms = []
for site in structure:
if site.species_string in ["S", "Se", "Te"]:
sulfur_atoms.append(site)
else:
metal_atoms.append(site)
z_coords_metal = []
for site in metal_atoms:
z_coords_metal.append(site.frac_coords[2])
z_min_metal = min(z_coords_metal)
z_max_metal = max(z_coords_metal)
z_middle = (z_min_metal + z_max_metal) / 2.0
top_layer_metal = []
for site in metal_atoms:
if site.frac_coords[2] > z_middle:
top_layer_metal.append(site)
if not top_layer_metal:
raise ValueError(f"Cannot distinguish the top metal atoms, please check the input structure.")
selected_site = top_layer_metal[0]
x = selected_site.frac_coords[0]
y = selected_site.frac_coords[1]
structure.append(atom_type, [x, y, z_middle])
writer = CifWriter(structure)
writer.write_file(output_file)
if __name__ == "__main__":
input_cif = "c2db-2832-WSe2-_shixc2db-2696-MoS2-_shi_0"
metals = ["Cu"]
for metal in metals:
insert_atom_M_TM_X(input_cif, metal, f"{metal}.cif")
|
@JuJueTanWan Thanks for sending through the file and code snippet. However I cannot recreate the issue (I didn't look into the custom 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:
The cif file:
|
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. |
By default, CifParser performs a primitive cell reduction since this is generally desired for calculations. If you prefer not to, you can always specify |
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
The text was updated successfully, but these errors were encountered: