First, let's load in MagresAtoms
from the magres
module, so we can load the .magres file:
from __future__ import print_function
import warnings
warnings.filterwarnings("ignore")
%pylab inline
from magres.atoms import MagresAtoms
atoms = MagresAtoms.load_magres('../samples/glycine-relaxed.magres')
print("We have", len(atoms), "atoms")
Populating the interactive namespace from numpy and matplotlib We have 20 atoms
We now have the atomic and magres data in the atoms
variable. There are 20 atoms because there are two glycine molecules in our unit cell.
Suppose we want to show the anistropy as well as the isotropic shielding. In this case, we can loop over all the hydrogen atoms with a for
loop and print out the ms.iso
and ms.aniso
properties of the atom
:
for atom in atoms.species('H'):
print(atom, atom.ms.iso, atom.ms.aniso)
1H1 21.260057521 24.0918885837 1H2 18.3481040425 30.1801849788 1H3 25.0518856127 15.2526591505 1H4 27.1289715665 7.67766255334 1H5 27.3806922257 -5.11250236358 1H6 21.260135207 24.0959617751 1H7 18.3477922956 30.1774257926 1H8 25.0521845075 15.2530187323 1H9 27.1295911445 7.67488078113 1H10 27.3808522391 -5.11108086678
Add some formatting to make it more readable:
print("atom\tiso\taniso")
for atom in atoms.species('H'):
print("{}\t{:.2f}\t{:.2f}".format(atom, atom.ms.iso, atom.ms.aniso))
atom iso aniso 1H1 21.26 24.09 1H2 18.35 30.18 1H3 25.05 15.25 1H4 27.13 7.68 1H5 27.38 -5.11 1H6 21.26 24.10 1H7 18.35 30.18 1H8 25.05 15.25 1H9 27.13 7.67 1H10 27.38 -5.11
If we want the chemical shifts, we also need to set a reference on the hydrogens. Let's do that, with a reference of 40.0 chosen arbitrarily:
atoms.species('H').set_reference(40.0)
and printing out the chemical shift and anisotropy
print("atom\tcs\taniso")
for atom in atoms.species('H'):
print("{}\t{:.2f}\t{:.2f}".format(atom, atom.ms.cs, atom.ms.aniso))
atom cs aniso 1H1 18.74 24.09 1H2 21.65 30.18 1H3 14.95 15.25 1H4 12.87 7.68 1H5 12.62 -5.11 1H6 18.74 24.10 1H7 21.65 30.18 1H8 14.95 15.25 1H9 12.87 7.67 1H10 12.62 -5.11