materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.52k stars 865 forks source link

io.lammps.data.LammpsData does not read charge from structure #2240

Open chc273 opened 3 years ago

chc273 commented 3 years ago

Describe the bug

For a structure with decorated atomic charges, I would expect LammpsData.from_structure(structure, atom_style='charge') to read the atom charges from the structure. However, this is not the case and the charges are all assigned zero.

To Reproduce

from pymatgen.core import Structure
from pymatgen.io.lammps.data import LammpsData

cif = "# generated using pymatgen\ndata_NaCl\n_symmetry_space_group_name_H-M   'P 1'\n_cell_length_a   2.66700000\n_cell_length_b   2.66700000\n_cell_length_c   2.66700000\n_cell_angle_alpha   90.00000000\n_cell_angle_beta   90.00000000\n_cell_angle_gamma   90.00000000\n_symmetry_Int_Tables_number   1\n_chemical_formula_structural   NaCl\n_chemical_formula_sum   'Na1 Cl1'\n_cell_volume   18.97007496\n_cell_formula_units_Z   1\nloop_\n _symmetry_equiv_pos_site_id\n _symmetry_equiv_pos_as_xyz\n  1  'x, y, z'\nloop_\n _atom_type_symbol\n _atom_type_oxidation_number\n  Na+  1.0\n  Cl-  -1.0\nloop_\n _atom_site_type_symbol\n _atom_site_label\n _atom_site_symmetry_multiplicity\n _atom_site_fract_x\n _atom_site_fract_y\n _atom_site_fract_z\n _atom_site_occupancy\n  Na+  Na0  1  0.00000000  0.00000000  0.00000000  1.0\n  Cl-  Cl1  1  0.50000000  0.50000000  0.50000000  1.0\n"

s = Structure.from_str(cif, fmt='cif')

print(s)  ## each atom has charges

ld = LammpsData.from_structure(s, atom_style='charge')
ld.write_file('data.static') 

The data.static file is as follows

Generated by pymatgen.io.lammps.data.LammpsData

2  atoms

2  atom types

0.000000 2.667000  xlo xhi
0.000000 2.667000  ylo yhi
0.000000 2.667000  zlo zhi

Masses

1  22.989769
2  35.453000

Atoms

1  1 0.0000 0.000000 0.000000 0.000000
2  2 0.0000 1.333500 1.333500 1.333500

you can see that the atom charges (the third column in Atoms) are all zeros.

Expected behavior

Atom charges should not be zero if structure is decorated with atom charges.

Desktop (please complete the following information):

JiQi535 commented 3 years ago

It seems that the oxidation_states should have been considered as "charge" in the site_properties of a structure.