Skip to content

Commit a6aa3a6

Browse files
jaclark5daico007
andauthored
Lammps lj unit charges (#1086)
* Produce n=2 when ports are not capped * Add option to not scale charges in lj units, and update docs for consistency * Update mbuild/formats/lammpsdata.py Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com> --------- Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>
1 parent 3ed8e4a commit a6aa3a6

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

mbuild/formats/lammpsdata.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def write_lammpsdata(
3737
sigma_conversion_factor=None,
3838
epsilon_conversion_factor=None,
3939
mass_conversion_factor=None,
40+
charge_conversion_factor=True,
4041
zero_dihedral_weighting_factor=False,
4142
moleculeID_offset=1,
4243
):
@@ -52,51 +53,56 @@ def write_lammpsdata(
5253
ParmEd structure object
5354
filename : str
5455
Path of the output file
55-
atom_style: str
56+
atom_style: str, optional, default='full'
5657
Defines the style of atoms to be saved in a LAMMPS data file. The
5758
following atom styles are currently supported:
5859
'full', 'atomic', 'charge', 'molecular'
5960
see http://lammps.sandia.gov/doc/atom_style.html for more information
6061
on atom styles.
61-
unit_style: str
62-
Defines to unit style to be save in a LAMMPS data file. Defaults to
63-
'real' units. Current styles are supported: 'real', 'lj'
64-
see https://lammps.sandia.gov/doc/99/units.html for more information
65-
on unit styles
66-
mins : list
67-
minimum box dimension in x, y, z directions, nm
68-
maxs : list
69-
maximum box dimension in x, y, z directions, nm
70-
pair_coeff_label : str
62+
unit_style : str, optional, default='real'
63+
Defines to unit style to be save in a LAMMPS data file. Current styles
64+
are supported: 'real', 'lj', see lammps unit style documentation:
65+
https://lammps.sandia.gov/doc/99/units.html for more information.
66+
mins : list, optional, default=None
67+
Minimum box dimension in x, y, z directions, nm
68+
maxs : list, optional, default=None
69+
Maximum box dimension in x, y, z directions, nm
70+
pair_coeff_label : str, optional, default=None
7171
Provide a custom label to the pair_coeffs section in the lammps data
72-
file. Defaults to None, which means a suitable default will be chosen.
73-
detect_forcefield_style: boolean
72+
file. A value of None means a suitable default will be chosen.
73+
detect_forcefield_style : bool, optional, default=True
7474
If True, format lammpsdata parameters based on the contents of
7575
the parmed Structure
76-
use_urey_bradleys: boolean
76+
use_urey_bradleys : bool, optional, default=False
7777
If True, will treat angles as CHARMM-style angles with urey bradley
7878
terms while looking for `structure.urey_bradleys`
79-
use_rb_torsions:
79+
use_rb_torsions : bool, optional, default=True
8080
If True, will treat dihedrals OPLS-style torsions while looking for
8181
`structure.rb_torsions`
82-
use_dihedrals:
82+
use_dihedrals : bool, optional, default=False
8383
If True, will treat dihedrals as CHARMM-style dihedrals while looking
8484
for `structure.dihedrals`
85-
zero_dihedral_weighting_factor:
85+
zero_dihedral_weighting_factor : bool, optional, default=False
8686
If True, will set weighting parameter to zero in CHARMM-style dihedrals.
8787
This should be True if the CHARMM dihedral style is used in non-CHARMM forcefields.
88-
sigma_conversion_factor: None, float
88+
sigma_conversion_factor : float, optional, default=None
8989
If unit_style is set to 'lj', then sigma conversion factor is used to non-dimensionalize.
90-
Assume to be in units of nm. Default is None. If None, will take the largest sigma value in
90+
Assume to be in units of nm. If None, will take the largest sigma value in
9191
the structure.atoms.sigma values.
92-
epsilon_conversion_factor: None, float
92+
epsilon_conversion_factor : float, optional, default=None
9393
If unit_style is set to 'lj', then epsilon conversion factor is used to non-dimensionalize.
94-
Assume to be in units of kCal/mol. Default is None. If None, will take the largest epsilon value in
94+
Assume to be in units of kCal/mol. If None, will take the largest epsilon value in
9595
the structure.atoms.epsilon values.
96-
mass_conversion_factor: None, float
96+
mass_conversion_factor : float, optional, default=None
9797
If unit_style is set to 'lj', then mass conversion factor is used to non-dimensionalize.
98-
Assume to be in units of amu. Default is None. If None, will take the largest mass value in
98+
Assume to be in units of amu. If None, will take the largest mass value in
9999
the structure.atoms.mass values.
100+
charge_conversion_factor : bool, optional, default=True
101+
If unit_style is set to 'lj', then charge conversion factor may or may not be used to
102+
non-dimensionalize. Assume to be in elementary charge units. If ``True``, the charges
103+
are scaled by ``np.sqrt(4*np.pi()*eps_0*sigma_conversion_factor*epsilon_conversion_factor)``.
104+
If ``False``, the charges are not scaled and the user must be wary to choose the dielectric
105+
constant properly, which may be more convenient to implement an implicit solvent.
100106
moleculeID_offset : int , optional, default=1
101107
Since LAMMPS treats the MoleculeID as an additional set of information
102108
to identify what molecule an atom belongs to, this currently
@@ -287,16 +293,17 @@ def write_lammpsdata(
287293
)
288294
# Convert coordinates and charges to LJ units
289295
xyz = xyz / sigma_conversion_factor
290-
charges = (charges * ELEM_TO_COUL) / np.sqrt(
291-
4
292-
* np.pi
293-
* sigma_conversion_factor
294-
* NM_TO_ANG**-1
295-
* epsilon_conversion_factor
296-
* KCAL_TO_KJ
297-
* epsilon_0
298-
* 10**-6
299-
)
296+
if charge_conversion_factor:
297+
charges = (charges * ELEM_TO_COUL) / np.sqrt(
298+
4
299+
* np.pi
300+
* sigma_conversion_factor
301+
* NM_TO_ANG**-1
302+
* epsilon_conversion_factor
303+
* KCAL_TO_KJ
304+
* epsilon_0
305+
* 10**-6
306+
)
300307
charges[np.isinf(charges)] = 0
301308
else:
302309
sigma_conversion_factor = 1

0 commit comments

Comments
 (0)