Skip to content

Commit

Permalink
Fixing some doctests. (#4118)
Browse files Browse the repository at this point in the history
Towards #3925 
* Solved failing doctests in `core/universe.py`, `lib/util.py`, and `lib/transformations.py`
  • Loading branch information
AHMED-salah00 authored Apr 11, 2023
1 parent 30baa14 commit 210e05c
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 18 deletions.
30 changes: 22 additions & 8 deletions package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,12 @@ def add_TopologyAttr(self, topologyattr, values=None):
-------
For example to add bfactors to a Universe:
>>> u.add_TopologyAttr('bfactors')
>>> u.atoms.bfactors
array([ 0., 0., 0., ..., 0., 0., 0.])
>>> import MDAnalysis as mda
>>> from MDAnalysis.tests.datafiles import PSF, DCD
>>> u = mda.Universe(PSF, DCD)
>>> u.add_TopologyAttr('tempfactors')
>>> u.atoms.tempfactors
array([0., 0., 0., ..., 0., 0., 0.])
.. versionchanged:: 0.17.0
Can now also add TopologyAttrs with a string of the name of the
Expand Down Expand Up @@ -863,8 +866,15 @@ def del_TopologyAttr(self, topologyattr):
-------
For example to remove bfactors to a Universe:
>>> u.del_TopologyAttr('bfactors')
>>> hasattr(u.atoms[:3], 'bfactors')
>>> import MDAnalysis as mda
>>> from MDAnalysis.tests.datafiles import PSF, DCD
>>> u = mda.Universe(PSF, DCD)
>>> u.add_TopologyAttr('tempfactors')
>>> hasattr(u.atoms[:3], 'tempfactors')
True
>>>
>>> u.del_TopologyAttr('tempfactors')
>>> hasattr(u.atoms[:3], 'tempfactors')
False
Expand Down Expand Up @@ -987,9 +997,12 @@ def add_Residue(self, segment=None, **attrs):
Adding a new GLY residue, then placing atoms within it:
>>> newres = u.add_Residue(segment=u.segments[0], resid=42, resname='GLY')
>>> import MDAnalysis as mda
>>> from MDAnalysis.tests.datafiles import PSF, DCD
>>> u = mda.Universe(PSF, DCD)
>>> newres = u.add_Residue(segment=u.segments[0], resid=42, resname='GLY', resnum=0)
>>> u.atoms[[1, 2, 3]].residues = newres
>>> u.select_atoms('resname GLY and resid 42')
>>> u.select_atoms('resname GLY and resid 42 and resnum 0')
<AtomGroup with 3 atoms>
"""
Expand Down Expand Up @@ -1407,6 +1420,7 @@ def from_smiles(cls, smiles, sanitize=True, addHs=True,
--------
To create a Universe with 10 conformers of ethanol:
>>> from rdkit.Chem import AllChem
>>> u = mda.Universe.from_smiles('CCO', numConfs=10)
>>> u
<Universe with 9 atoms>
Expand All @@ -1416,7 +1430,7 @@ def from_smiles(cls, smiles, sanitize=True, addHs=True,
To use a different conformer generation algorithm, like ETKDGv3:
>>> u = mda.Universe.from_smiles('CCO', rdkit_kwargs=dict(
params=AllChem.ETKDGv3()))
... params=AllChem.ETKDGv3()))
>>> u.trajectory
<RDKitReader with 1 frames of 9 atoms>
Expand Down
Loading

0 comments on commit 210e05c

Please sign in to comment.