from __future__ import print_function
import warnings
warnings.filterwarnings("ignore")
%pylab inline
from magres.atoms import MagresAtoms
Populating the interactive namespace from numpy and matplotlib
atoms = MagresAtoms.load_magres('../samples/ethanol-all.magres')
atoms
is now a collection containing all the atoms in the system
atoms
<magres.atom.MagresAtoms - 9 atoms>
MagresAtoms
behaves like a list
, you can use standard builtin functions like len
on it, which returns the number of atoms
len(atoms)
9
Again, like a list
, you can iterate over all the atoms
for atom in atoms:
print(atom)
1H1 1H2 1H3 1H4 1H5 1H6 13C1 13C2 17O1
There are shortcuts for selecting a particular atom of a particular species. The following code picks out the first carbon atom
atoms.C1
<magres.atom.MagresAtom - 13C1>
Atoms are objects and have properties, such as position
, which is returned as a numpy array
atoms.C1.position
array([-0.004, -0.004, -0.004])
You can select subsets of atoms, which also behave like lists. For example, to select all hydrogen atoms in the system
atoms.species("H")
<magres.atom.MagresAtomsView - 6 atoms>