pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

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

Open chc273 opened this issue 3 years ago • 1 comments

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):

  • OS: [e.g. Mac,Windows,Linux]
  • Version [v2022.0.14]

chc273 avatar Sep 07 '21 00:09 chc273

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

JiQi535 avatar Sep 07 '21 00:09 JiQi535