# Problem with precision of variables

Hi,

I’m having trouble with the precision of variables in LAMMPS. The simplest way I can reproduce the problem is with the input file below. I’ve copied the potential energy into two variables and printed them after each run command.

variable pe1 equal pe
thermo_style custom pe v_pe1
thermo_modify format float %20.16f

run 0

variable pe2 equal v_pe1
thermo_style custom pe v_pe1 v_pe2
thermo_modify format float %20.16f

run 0

The output below shows the last variable (pe2) truncated to 6 decimals instead of the expected 16. Is there a reason for this?

PotEng pe1
2644.0551081889525449 2644.0551081889525449
PotEng pe1 pe2
2644.0551081889520901 2644.0551081889520901 2644.0551080000000184

Thanks,

Brian

Hi,

I'm having trouble with the precision of variables in LAMMPS. The simplest
way I can reproduce the problem is with the input file below. I've copied
the potential energy into two variables and printed them after each run
command.

a) please always state which version of LAMMPS you are using
b) please always provide a *complete* input, not just a few lines.

in your case, it is also important to know, if you use any GPU acceleration.

axel.

I’m using the May 5th, 2012 version of LAMMPS without any GPU acceleration

Here’s the rest of my input file:

units real
atom_style full
boundary p p p

mass 1 1.007940
mass 2 10.81100
mass 3 12.01070
mass 4 14.00670
mass 5 15.99940
mass 6 58.69340

bond_style harmonic
angle_style harmonic
dihedral_style charmm
improper_style umbrella
pair_style lj/cut/coul/long 10.0 10.0
pair_modify tail yes
kspace_style pppm 1.0e-4
special_bonds lj 0.0 0.0 0.5 coul 0.0 0.0 0.5

bond_coeff 1 469 1.400
bond_coeff 2 367 1.080
bond_coeff 3 317 1.510
bond_coeff 4 340 1.090
bond_coeff 5 268 1.529
bond_coeff 6 320 1.410
bond_coeff 7 320 1.410
bond_coeff 8 553 0.945
bond_coeff 9 350 1.020
bond_coeff 10 350 0.995
bond_coeff 11 350 1.090
bond_coeff 12 350 0.975
bond_coeff 13 350 0.980
bond_coeff 14 350 1.480
bond_coeff 15 350 1.440
bond_coeff 16 525 1.390
bond_coeff 17 350 1.365
bond_coeff 18 350 1.460
bond_coeff 19 525 1.345
bond_coeff 20 525 1.345
bond_coeff 21 350 1.350
bond_coeff 22 350 1.325
bond_coeff 23 700 1.230
bond_coeff 24 350 1.540
bond_coeff 25 350 1.420
bond_coeff 26 175 1.855
bond_coeff 27 350 1.570
bond_coeff 28 350 1.530

angle_coeff 1 63.00 120.0
angle_coeff 2 35.00 120.0
angle_coeff 3 70.00 120.0
angle_coeff 4 35.00 109.5
angle_coeff 5 33.00 107.8
angle_coeff 6 50.00 109.5
angle_coeff 7 37.50 110.7
angle_coeff 8 35.00 109.5
angle_coeff 9 60.00 109.5
angle_coeff 10 35.00 109.5
angle_coeff 11 55.00 108.5
angle_coeff 12 50.00 109.5
angle_coeff 13 58.35 112.7
angle_coeff 14 50.00 120.000
angle_coeff 15 50.00 109.471
angle_coeff 16 50.00 104.510
angle_coeff 17 50.00 90.000

dihedral_coeff 1 0.6250 2 180 0.25
dihedral_coeff 2 0.6250 2 180 0.50
dihedral_coeff 3 0.5000 2 180 0.25
dihedral_coeff 4 0.5000 2 180 0.50
dihedral_coeff 5 3.1250 2 180 0.25
dihedral_coeff 6 3.1250 2 180 0.50
dihedral_coeff 7 3.1250 6 180 0.25
dihedral_coeff 8 3.1250 6 180 0.50
dihedral_coeff 9 0.0833 6 180 0.25
dihedral_coeff 10 0.0833 6 180 0.50
dihedral_coeff 11 6.2500 2 180 0.25
dihedral_coeff 12 6.2500 2 180 0.50
dihedral_coeff 13 0.1111 3 180 0.25
dihedral_coeff 14 0.1111 3 180 0.50
dihedral_coeff 15 0.3333 3 180 0.25
dihedral_coeff 16 0.3333 3 180 0.50

improper_coeff 1 13.33 0

pair_coeff 1 1 lj/cut/coul/long 0.066 3.5 1.0
pair_coeff 1 2 lj/cut/coul/long 0.044497 2.95804 1.0
pair_coeff 1 3 lj/cut/coul/long 0.067971 3.524911 1.0
pair_coeff 1 4 lj/cut/coul/long 0.044497 2.910326 1.0
pair_coeff 1 5 lj/cut/coul/long 0.105925 3.304542 1.0
pair_coeff 1 6 lj/cut/coul/long 0.00 0.00 1.0
pair_coeff 2 2 lj/cut/coul/long 0.03 2.5 1.0
pair_coeff 2 3 lj/cut/coul/long 0.045826 2.979094 1.0
pair_coeff 2 4 lj/cut/coul/long 0.03 2.459675 1.0
pair_coeff 2 5 lj/cut/coul/long 0.071414 2.792848 1.0
pair_coeff 2 6 lj/cut/coul/long 0.00 0.00 1.0
pair_coeff 3 3 lj/cut/coul/long 0.07 3.55 1.0
pair_coeff 3 4 lj/cut/coul/long 0.045826 2.931041 1.0
pair_coeff 3 5 lj/cut/coul/long 0.109087 3.328062 1.0
pair_coeff 3 6 lj/cut/coul/long 0.00 0.00 1.0
pair_coeff 4 4 lj/cut/coul/long 0.03 2.42 1.0
pair_coeff 4 5 lj/cut/coul/long 0.071414 2.747799 1.0
pair_coeff 4 6 lj/cut/coul/long 0.00 0.00 1.0
pair_coeff 5 5 lj/cut/coul/long 0.17 3.12 1.0
pair_coeff 5 6 lj/cut/coul/long 0.00 0.00 1.0
pair_coeff 6 6 lj/cut/coul/long 0.00 0.00 1.0

variable pe1 equal pe
thermo_style custom pe v_pe1
thermo_modify format float %20.16f

run 0

variable pe2 equal v_pe1
thermo_style custom pe v_pe1 v_pe2
thermo_modify format float %20.16f

run 0

I'm using the May 5th, 2012 version of LAMMPS without any GPU acceleration

please update to a current version. the internal precision has been
adjusted since. 16 digits is still beyond the "capacity" of double
precision floating point numbers. due to the way how variables in
LAMMPS work internally, you cannot expect the full double precision
detail let alone IEEE 754 compliance either. in the best case you get
a little less.

with setting pppm precision as low as 1e-4 this is a pointless exercise, anyway.

axel.

I'm using the May 5th, 2012 version of LAMMPS without any GPU acceleration

please update to a current version. the internal precision has been
adjusted since. 16 digits is still beyond the "capacity" of double
precision floating point numbers. due to the way how variables in
LAMMPS work internally, you cannot expect the full double precision
detail let alone IEEE 754 compliance either. in the best case you get
a little less.

with setting pppm precision as low as 1e-4 this is a pointless exercise, anyway.

not to mention a LJ cutoff of 1.0 angstrom. what is the reason for that?

axel.

Updating to a later version solved the problem. Thanks very much for the help!

The 1.0 was just a flag I set in a modified version of the LJ pair style, nothing to worry about there.

Brian