From 73acc9bf9631c135dfd40322e121f379abfce198 Mon Sep 17 00:00:00 2001 From: nataliyah123 Date: Tue, 2 Apr 2024 04:04:23 +0500 Subject: [PATCH] lammps.py errors (#4458) * contributes to #3925 * fix lammps.py doctest errors --- package/MDAnalysis/coordinates/LAMMPS.py | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/package/MDAnalysis/coordinates/LAMMPS.py b/package/MDAnalysis/coordinates/LAMMPS.py index 0227ed742c..e772a3e392 100644 --- a/package/MDAnalysis/coordinates/LAMMPS.py +++ b/package/MDAnalysis/coordinates/LAMMPS.py @@ -66,22 +66,33 @@ :class:`~MDAnalysis.topology.LAMMPSParser.DATAParser`) together with a LAMMPS DCD with "*real*" provide the keyword *format="LAMMPS*":: - >>> u = MDAnalysis.Universe("lammps.data", "lammps_real.dcd", format="LAMMPS") + >>> import MDAnalysis + >>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2 + >>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS") -If the trajectory uses *units nano* then use :: +If the trajectory uses *units nano* then use - >>> u = MDAnalysis.Universe("lammps.data", "lammps_nano.dcd", format="LAMMPS", + >>> import MDAnalysis + >>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2 + >>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS", ... lengthunit="nm", timeunit="ns") To scan through a trajectory to find a desirable frame and write to a LAMMPS data file, ->>> for ts in u.trajectory: -... # analyze frame -... if take_this_frame == True: -... with mda.Writer('frame.data') as W: -... W.write(u.atoms) -... break + >>> import MDAnalysis + >>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2 + >>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS", + ... lengthunit="nm", timeunit="ns") + >>> take_this_frame = False + >>> for ts in u.trajectory: + ... # analyze frame + ... if ts.frame == 4: + ... take_this_frame = True + ... if take_this_frame == True: + ... with MDAnalysis.Writer('frame.data') as W: + ... W.write(u.atoms) + ... break Note ----