Skip to content

Commit 03eef45

Browse files
Fix incorrect unit conversion factors in units.py (#5053)
* fix #5051 * The conversion factors for A/fs, A/ms and A/us have been revised and corrected. * update corresponding test cases by adjusting reference velocities * Update position and velocity formatting in LAMMPS output to 10 decimals (required for accurate round-trip tests with velocities) * add additional velocity units: A/ns to speed units * add additional representations for existing velocities Å/us, Å/µs, Å/fs, Å/ms * add tests for unit conversion with unicode characters * blackened units.py and test)units.py * update CHANGELOG (moved recent entries to top) * update AUTHORS --------- Co-authored-by: Oliver Beckstein <[email protected]>
1 parent 19e675b commit 03eef45

File tree

6 files changed

+116
-92
lines changed

6 files changed

+116
-92
lines changed

package/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Chronological list of authors
262262
- Sirsha Ganguly
263263
- Amruthesh Thirumalaiswamy
264264
- Ch Zhang
265+
- Raúl Lois-Cuns
265266

266267
External code
267268
-------------

package/CHANGELOG

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ The rules for this file:
1616
-------------------------------------------------------------------------------
1717
??/??/?? IAlibay, orbeckst, BHM-Bob, TRY-ER, Abdulrahman-PROG, pbuslaev,
1818
yuxuanzhuang, yuyuan871111, tanishy7777, tulga-rdn, Gareth-elliott,
19-
hmacdope, tylerjereddy, cbouy, talagayev, DrDomenicoMarson, amruthesht,
20-
p-j-smith, gitzhangch
21-
19+
hmacdope, tylerjereddy, cbouy, talagayev, DrDomenicoMarson, amruthesht,
20+
p-j-smith, gitzhangch, raulloiscuns
2221

2322
* 2.10.0
2423

2524
Fixes
25+
* Fix incorrect conversion factors for speed units A/fs, A/us, A/ms
26+
in MDAnalysis.units (Issue #5051, PR #5053)
27+
* `analysis.polymer.sort_backbone` is now working for discontinuous polymers
28+
and does not result in an infinite loop (Issue #5112, PR #5113)
2629
* Fix atom selection parsing to allow escaping keywords with a backslash
2730
(Issue #5111, PR #5119)
28-
* Fix DCDWriter to correctly write unit cell angles as cosines following
31+
* Fix DCDWriter to correctly write unit cell angles as cosines following
2932
NAMD/VMD convention (Issue #5069)
3033
* Fixed an integer overflow in large DCD file seeks on Windows
3134
(Issue #4879, PR #5086)
@@ -37,19 +40,19 @@ Fixes
3740
* Fixes bug in `analysis/gnm.py`: `closeContactGNMAnalysis`: correct the
3841
`residue_index_map` generation when selection is not `protein`.
3942
(Issue #4924, PR #4961)
40-
* Reads `segids` column in `PDBParser` from 73-76 instead of 67-76 to
41-
align the standard of a PDBReader (e.g., Chimera, CHARMM, Gemmi).
43+
* Reads `segids` column in `PDBParser` from 73-76 instead of 67-76 to
44+
align the standard of a PDBReader (e.g., Chimera, CHARMM, Gemmi).
4245
(Issue #4948, PR #5001)
4346
* Fixes the benchmark `SimpleRmsBench` in `benchmarks/analysis/rms.py`
4447
by changing the way weights for RMSD are calculated, instead of
4548
directly passing them. (Issue #3520, PR #5006)
46-
* `analysis.polymer.sort_backbone` is now working for discontinuous polymers
47-
and does not result in an infinite loop (Issue #5112, PR #5113)
4849

4950
Enhancements
50-
* Improved performance of `analysis.rdf.InterRDF_s` > 20-fold
51+
* Add conversion factor for speed unit A/ns and additional representations (Å/fs, A/µs,
52+
Å/μs, Å/ms) (PR #5053)
53+
* Improved performance of `analysis.rdf.InterRDF_s` > 20-fold
5154
by using vectorized NumPy calculations. (Issue #5067, PR #5073)
52-
* Parallelize `analysis.rdf.InterRDF` and `analysis.rdf.InterRDF` (Issue #4675)
55+
* Parallelize `analysis.rdf.InterRDF` and `analysis.rdf.InterRDF` (Issue #4675)
5356
* Support for Python 3.14 was added (PR #5121).
5457
* Added support for reading and processing streamed data in `coordinates.base`
5558
with new `StreamFrameIteratorSliced` and `StreamReaderBase` (Issue #4827, PR #4923)
@@ -68,13 +71,13 @@ Enhancements
6871
* Improve parsing of topology information from LAMMPS dump files to allow
6972
reading of mass, charge and element attributes. (Issue #3449, PR #4995)
7073
* Added timestep support for XDR writers and readers (Issue #4905, PR #4908)
71-
* New feature in `Universe`: `set_groups`. This function allows updating
72-
`_topology`, `residues` (ResidueGroup), `segments` (SegmentGroup) in
73-
the `Universe` using user-provided atomwise `resids` and/or `segids`.
74-
(Issue #4948 #2874, PR #4965)
75-
* Adds an argument `force_chainids_to_segids` in `PDBParser`: this will
76-
force the use of ChainID as the segID when reading PDB (it is helpful
77-
if the segment IDs (segids) are partially missing in the PDB file).
74+
* New feature in `Universe`: `set_groups`. This function allows updating
75+
`_topology`, `residues` (ResidueGroup), `segments` (SegmentGroup) in
76+
the `Universe` using user-provided atomwise `resids` and/or `segids`.
77+
(Issue #4948 #2874, PR #4965)
78+
* Adds an argument `force_chainids_to_segids` in `PDBParser`: this will
79+
force the use of ChainID as the segID when reading PDB (it is helpful
80+
if the segment IDs (segids) are partially missing in the PDB file).
7881
(Issue #4948 #2874, PR #4965)
7982
* Enables parallelization for analysis.lineardensity.LinearDensity
8083
(Issue #4678, PR #5007)
@@ -84,18 +87,19 @@ Enhancements
8487
so that it gets passed through from the calling functions and classes
8588
(PR #5038)
8689
* Moved distopia checking function to common import location in
87-
MDAnalysisTest.util (PR #5038)
90+
MDAnalysisTest.util (PR #5038)
8891
* Enables parallelization for `analysis.polymer.PersistenceLength` (Issue #4671, PR #5074)
8992

9093

9194
Changes
95+
* Output precision for LAMMPS Data files set to 10 decimals (PR #5053)
9296
* Support for Python 3.10 was removed, in line with SPEC0 (PR #5121).
9397
* Refactored the RDKit converter code to move the inferring code in a separate
9498
`RDKitInferring` module. The bond order and charges inferrer has been move to
9599
an `MDAnalysisInferrer` dataclass in there. (PR #4305)
96100
* Removed undocumented and unused attribute
97101
`analysis.lineardensity.LinearDensity.totalmass` (PR #5007)
98-
* Remove `default` channel from RTD conda env. (Issue # 5036, PR # 5037)
102+
* Remove `default` channel from RTD conda env. (Issue # 5036, PR # 5037)
99103

100104

101105
Deprecations
@@ -119,7 +123,7 @@ Fixes
119123
the function to prevent shared state. (Issue #4655)
120124

121125
Enhancements
122-
* Improve distopia backend support in line with new functionality available
126+
* Improve distopia backend support in line with new functionality available
123127
in distopia >= 0.3.1 (PR #4734)
124128
* Addition of 'water' token for water selection (Issue #4839)
125129
* Enables parallelization for analysis.density.DensityAnalysis
@@ -145,7 +149,7 @@ Changes
145149

146150
11/11/24 IAlibay, HeetVekariya, marinegor, lilyminium, RMeli,
147151
ljwoods2, aditya292002, pstaerk, PicoCentauri, BFedder,
148-
tyler.je.reddy, SampurnaM, leonwehrhan, kainszs, orionarcher,
152+
tyler.je.reddy, SampurnaM, leonwehrhan, kainszs, orionarcher,
149153
yuxuanzhuang, PythonFZ, laksh-krishna-sharma, orbeckst, MattTDavies,
150154
talagayev, aya9aladdin
151155

@@ -211,7 +215,7 @@ Enhancements
211215
* Explicitly mark `analysis.pca.PCA` as not parallelizable (Issue #4680)
212216
* Enables parallelization for analysis.bat.BAT (Issue #4663)
213217
* Enable parallelization for analysis.dihedrals.{Dihedral,Ramachandran,Janin}
214-
(Issue #4673)
218+
(Issue #4673)
215219
* Enables parallelization for analysis.dssp.dssp.DSSP (Issue #4674)
216220
* Enables parallelization for analysis.hydrogenbonds.hbond_analysis.HydrogenBondAnalysis (Issue #4664)
217221
* Improve error message for `AtomGroup.unwrap()` when bonds are not present.(Issue #4436, PR #4642)
@@ -244,9 +248,9 @@ Changes
244248
* As per NEP29, the minimum version of numpy has been raised to 1.23.
245249
We have opted to pin to 1.23.2 to ensure the same minimum numpy version
246250
is used from python 3.9 to 3.11 (Issue #4401, PR #4402)
247-
* updated tests that used assert_almost_equal(..., decimal={N}) with
251+
* updated tests that used assert_almost_equal(..., decimal={N}) with
248252
equivalent assert_allclose(... rtol=0, atol=1.5e-{N}) (issue modernize
249-
testing code #3743, PR Replaced numpy.testing.assert_almost_equal to
253+
testing code #3743, PR Replaced numpy.testing.assert_almost_equal to
250254
numpy.testing.assert_allclose #4438)
251255

252256
Deprecations
@@ -278,8 +282,8 @@ Deprecations
278282
(PR #4403)
279283

280284

281-
12/26/23 IAlibay, ianmkenney, PicoCentauri, pgbarletta, p-j-smith,
282-
richardjgowers, lilyminium, ALescoulie, hmacdope, HeetVekariya,
285+
12/26/23 IAlibay, ianmkenney, PicoCentauri, pgbarletta, p-j-smith,
286+
richardjgowers, lilyminium, ALescoulie, hmacdope, HeetVekariya,
283287
JoStoe, jennaswa, ljwoods2
284288

285289
* 2.7.0
@@ -297,7 +301,7 @@ Fixes
297301
RMSD of None
298302
* Fixes hydrogenbonds tutorial path to point to hbonds (Issue #4285, PR #4286)
299303
* Fix atom charge reading in PDBQT parser (Issue #4282, PR #4283)
300-
* Fix doctests failing from separated blocks of imports and
304+
* Fix doctests failing from separated blocks of imports and
301305
execution and incorrectly formatted test output (Issue #3925, PR #4366)
302306

303307
Enhancements
@@ -313,8 +317,8 @@ Enhancements
313317
* Added a warning about charge neutrality to the documentation of
314318
`DielectricConstant` (Issue #4262, PR #4263)
315319
* Add support for reading chainID info from prmtop amber topologies (PR #4007)
316-
* Add support for reading chainID info from GROMACS TPR topologies
317-
(Issue #3994, PR #4281)
320+
* Add support for reading chainID info from GROMACS TPR topologies
321+
(Issue #3994, PR #4281)
318322
* Add support for reading chainID info from Autodock PDBQT files (Issue #4207,
319323
PR #4284)
320324

@@ -328,7 +332,7 @@ Changes
328332
replacing the now deprecated `xdrlib` core Python library
329333
(PR #4271)
330334
* ConverterBase class moved from coordinates/base.py to converters/base.py (Issue #3404)
331-
* Results for WatsonCrickDist nucleic acids analysis are now stored in
335+
* Results for WatsonCrickDist nucleic acids analysis are now stored in
332336
`analysis.nucleicacids.WatsonCrickDist.results.distances` (Issue #3720, PR #3735)
333337

334338
Deprecations
@@ -345,7 +349,7 @@ Deprecations
345349
in favor of using `ResidueGroup`: using `List[Residue]` will be removed in release
346350
3.0.0; instead use a `ResidueGroup` (Issue #3720, PR #3735)
347351
* In `nucleicacids.WatsonCrickDist` the result `results.pair_distances` was
348-
deprecated and will be removed in 3.0.0; use `results.distances` (Issue #3720,
352+
deprecated and will be removed in 3.0.0; use `results.distances` (Issue #3720,
349353
PR #3735)
350354

351355

@@ -397,7 +401,7 @@ Changes
397401
of NEP29 (PR #4108).
398402
* Removed `-ffast-math` compiler flag to avoid potentially incorrect
399403
floating point results in MDAnalysis *and* other codes when
400-
MDAnalysis shared libraries are loaded --- see
404+
MDAnalysis shared libraries are loaded --- see
401405
https://moyix.blogspot.com/2022/09/someones-been-messing-with-my-subnormals.html
402406
(Issues #3821, #4211)
403407
* Atom ID representation order updated to match that of associated
@@ -428,7 +432,7 @@ Deprecations
428432
32 bit compatible versions. (Issue #3858, PR #4176)
429433

430434

431-
05/28/23 IAlibay, pgbarletta, mglagolev, hmacdope, manuel.nuno.melo, chrispfae,
435+
05/28/23 IAlibay, pgbarletta, mglagolev, hmacdope, manuel.nuno.melo, chrispfae,
432436
ooprathamm, MeetB7, BFedder, v-parmar, MoSchaeffler, jbarnoud, jandom,
433437
xhgchen, jaclark5, DrDomenicoMarson, AHMED-salah00, schlaicha,
434438
SophiaRuan, g2707, p-j-smith, tylerjereddy, xiki-tempula, richardjgowers,
@@ -492,13 +496,13 @@ Enhancements
492496
* Add distopia distance calculation library bindings as a selectable backend
493497
for `calc_bonds` in `MDA.lib.distances`. (Issue #3783, PR #3914)
494498
* AuxReaders are now pickle-able and copy-able (Issue #1785, PR #3887)
495-
* Add pickling support for Atom, Residue, Segment, ResidueGroup
499+
* Add pickling support for Atom, Residue, Segment, ResidueGroup
496500
and SegmentGroup. (PR #3953)
497501

498502
Changes
499503
* As per NEP29 the minimum supported Python version has been raised to 3.9
500504
(PR #4115).
501-
* einsum method for Einstein summation convention introduced to increase
505+
* einsum method for Einstein summation convention introduced to increase
502506
performance (Issue #2063, PR #4089)
503507
* Add progress bars to track the progress of _conclude() functions
504508
(_conclude_simple() and _conclude_fft()) in msd.py (Issue #4070, PR #4072)
@@ -558,24 +562,24 @@ Fixes
558562
* 2.4.0
559563

560564
Fixes
561-
* Update hbond analysis doc string to use exclusive bound language
565+
* Update hbond analysis doc string to use exclusive bound language
562566
(Issue #3847)
563567
* XTC and TRR readers now fail with IOError when a status except EOK (=0) is
564568
detected on reading a frame instead of silently continuing
565569
* Consolidate license files across MDAnalysis library packages (PR #3939)
566570
* Kwargs passed through to `MemoryReader` when using `transfer_to_memory()`
567571
and `in_memory=True`.
568-
* NoDataError raised on empty atomgroup provided to `DCDReader.timeseries`
572+
* NoDataError raised on empty atomgroup provided to `DCDReader.timeseries`
569573
was changed to ValueError (see #3901). A matching ValueError was added to
570-
`MemoryReader.timeseries`(PR #3890).
574+
`MemoryReader.timeseries`(PR #3890).
571575
* Removes ``pbc`` kwarg from ``AtomGroup.wrap`` (Issue #3909)
572576
* LAMMPSDump Reader translates the box to the origin (#3741)
573577
* hbond analysis: access hbonds results through new results member in count_by_ids() and count_by_type()
574578
* Auxiliary; determination of representative frames: Removed undefined
575579
behaviour for cutoff values < -1 (PR # 3749)
576580
* Fixes distances.between not always returning AtomGroup (Issue #3794)
577581
* Upgrade to chemfiles 0.10.3 (Issue #3798)
578-
* fixes guessed_attributes and read_attributes methods of the Topology class, as
582+
* fixes guessed_attributes and read_attributes methods of the Topology class, as
579583
those methods were giving unexpected results for some topology attributes
580584
(e.g. bonds, angles) (PR #3779).
581585

@@ -584,24 +588,24 @@ Enhancements
584588
(Issue #3841, PR #3842)
585589
* MDAnalysis now follows PEP621 (PR #3528)
586590
* Added a reader for GROMACS TNG files based on PyTNG (PR #3765,
587-
Issue #3237, partially addressing Issue #865)
588-
* Added ability for hbond analysis to use types when resnames are not
591+
Issue #3237, partially addressing Issue #865)
592+
* Added ability for hbond analysis to use types when resnames are not
589593
present (Issue #3847)
590594
* Added explanatory warnings when hbond analysis doesn't find any hbonds
591595
(Issue #3847)
592-
* Improve C content of libxdr Cython, add `read_direct` methods to read
596+
* Improve C content of libxdr Cython, add `read_direct` methods to read
593597
coordinates, velocities and forces directly into memoryviews of `Timestep`
594598
attributes, make `TRR` timestep have positions, velocities and forces on
595599
`__init__`. (Issue #3891 PR #3892).
596600
* Improve C content of libdcd Cython (Issue #3882, PR #3888)
597601
* The timeseries method for exporting coordinates from multiple frames to a
598602
NumPy array was added to ProtoReader (PR #3890)
599603
* MDAnalysis now officially supports py3.11 (Issue #3878)
600-
* LAMMPSDump Reader optionally unwraps trajectories with image flags upon
604+
* LAMMPSDump Reader optionally unwraps trajectories with image flags upon
601605
loading (Issue #3843)
602606
* LAMMPSDump Reader now imports velocities and forces (Issue #3843)
603607
* Minimum NumPy version for py3.11 is now set to 1.23.2.
604-
* Added decorator to check for an empty atom group, applied in topological
608+
* Added decorator to check for an empty atom group, applied in topological
605609
attributes(Issue #3837)
606610
* AuxReaders now have a memory_limit parameter to control when memory usage
607611
warnings are issued. (PR # 3749)

package/MDAnalysis/coordinates/LAMMPS.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
===============================================================================
2727
2828
Classes to read and write LAMMPS_ DCD binary trajectories, LAMMPS DATA files
29-
and LAMMPS dump files. Trajectories can be read regardless of system-endianness
30-
as this is auto-detected.
29+
and LAMMPS dump files. Trajectories can be read regardless of
30+
system-endianness as this is auto-detected.
3131
3232
LAMMPS can `write DCD`_ trajectories but unlike a `CHARMM trajectory`_
3333
(which is often called a DCD even though CHARMM itself calls them
@@ -81,7 +81,7 @@
8181
data file,
8282
8383
>>> import MDAnalysis
84-
>>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
84+
>>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
8585
>>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS",
8686
... lengthunit="nm", timeunit="ns")
8787
>>> take_this_frame = False
@@ -107,7 +107,8 @@
107107
108108
.. _LAMMPS: https://www.lammps.org/
109109
.. _write DCD: https://docs.lammps.org/dump.html
110-
.. _CHARMM trajectory: http://www.charmm.org/documentation/c36b1/dynamc.html#%20Trajectory
110+
.. _CHARMM trajectory:
111+
http://www.charmm.org/documentation/c36b1/dynamc.html#%20Trajectory
111112
.. _AKMA: http://www.charmm.org/documentation/c36b1/usage.html#%20AKMA
112113
.. _units real: https://docs.lammps.org/units.html
113114
.. _units command: https://docs.lammps.org/units.html
@@ -180,9 +181,8 @@ def __init__(self, *args, **kwargs):
180181
try:
181182
if units.unit_types[unit] != unit_type:
182183
raise TypeError(
183-
"LAMMPS DCDWriter: wrong unit {0!r} for unit type {1!r}".format(
184-
unit, unit_type
185-
)
184+
f"LAMMPS DCDWriter: wrong unit {unit} for "
185+
f"unit type {unit_type}"
186186
)
187187
except KeyError:
188188
errmsg = f"LAMMPS DCDWriter: unknown unit {unit}"
@@ -216,14 +216,11 @@ def __init__(self, dcdfilename, **kwargs):
216216
try:
217217
if units.unit_types[unit] != unit_type:
218218
raise TypeError(
219-
"LAMMPS DCDReader: wrong unit {0!r} for unit type {1!r}".format(
220-
unit, unit_type
221-
)
219+
f"LAMMPS DCDReader: wrong unit {unit} for "
220+
f"unit type {unit_type}"
222221
)
223222
except KeyError:
224-
raise ValueError(
225-
"LAMMPS DCDReader: unknown unit {0!r}".format(unit)
226-
)
223+
raise ValueError(f"LAMMPS DCDReader: unknown unit {unit}")
227224
super(DCDReader, self).__init__(dcdfilename, **kwargs)
228225

229226

@@ -344,15 +341,15 @@ def _write_atoms(self, atoms, data):
344341
x, y, z = coords
345342
self.f.write(
346343
f"{index:d} {moltag:d} {atype:d} {charge:f}"
347-
f" {x:f} {y:f} {z:f}\n"
344+
f" {x:.10f} {y:.10f} {z:.10f}\n"
348345
)
349346
else:
350347
for index, moltag, atype, coords in zip(
351348
indices, moltags, types, coordinates
352349
):
353350
x, y, z = coords
354351
self.f.write(
355-
f"{index:d} {moltag:d} {atype:d}" f" {x:f} {y:f} {z:f}\n"
352+
f"{index:d} {moltag:d} {atype:d} {x:.10f} {y:.10f} {z:.10f}\n"
356353
)
357354

358355
def _write_velocities(self, atoms):
@@ -365,7 +362,7 @@ def _write_velocities(self, atoms):
365362
)
366363
for index, vel in zip(indices, velocities):
367364
self.f.write(
368-
"{i:d} {x:f} {y:f} {z:f}\n".format(
365+
"{i:d} {x:.10f} {y:.10f} {z:.10f}\n".format(
369366
i=index, x=vel[0], y=vel[1], z=vel[2]
370367
)
371368
)
@@ -613,7 +610,8 @@ class DumpReader(base.ReaderBase):
613610
<https://docs.lammps.org/read_data.html>`__ in the lammps
614611
documentation for more information.
615612
**kwargs
616-
Other keyword arguments used in :class:`~MDAnalysis.coordinates.base.ReaderBase`
613+
Other keyword arguments used in
614+
:class:`~MDAnalysis.coordinates.base.ReaderBase`
617615
618616
619617
.. versionchanged:: 2.8.0
@@ -832,9 +830,8 @@ def _read_next_timestep(self):
832830
raise ValueError("No coordinate information detected")
833831
elif not self.lammps_coordinate_convention in convention_to_col_ix:
834832
raise ValueError(
835-
f"No coordinates following convention "
836-
"{self.lammps_coordinate_convention} found in "
837-
"timestep"
833+
"No coordinates following convention "
834+
f"{self.lammps_coordinate_convention} found in timestep"
838835
)
839836

840837
coord_cols = convention_to_col_ix[self.lammps_coordinate_convention]

0 commit comments

Comments
 (0)