예제 #1
0
    def test_isc(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "ethanol-isc.magres"))

        self.assertTrue(hasattr(atoms.C2, "isc"))
        self.assertTrue(hasattr(atoms.C2, "isc_orbital_p"))
        self.assertTrue(hasattr(atoms.C2, "isc_orbital_d"))
        self.assertTrue(hasattr(atoms.C2, "isc_spin"))
        self.assertTrue(hasattr(atoms.C2, "isc_fc"))

        self.assertEqual(len(atoms.C2.isc), len(atoms) - 1)

        perturb_atom = atoms.get('C', 2)

        for isc in atoms.C2.isc:
            self.assertEqual(isc.atom1, perturb_atom)
            self.assertEqual(isc.K_iso, numpy.trace(isc.K) / 3.0)

        # Check that the principal components are ordered by the Haeberlen convention
        for isc in atoms.C2.isc:
            self.assertTrue(
                abs(isc.K_evals[2] - isc.K_iso) >= abs(isc.K_evals[0] -
                                                       isc.K_iso))
            self.assertTrue(
                abs(isc.K_evals[0] - isc.K_iso) >= abs(isc.K_evals[1] -
                                                       isc.K_iso))
    def test(self):
        from magres.atoms import MagresAtoms

        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, 'ethanol-all.magres'))

        self.assertEqual(len(atoms), 9)

        for atom in atoms:
            "{} {}".format(atom, atom.ms.iso)

        atoms.species('H').set_reference(10.0)

        for atom in atoms.species('H'):
            "{} {}".format(atom, atom.ms.cs)

        for atom in atoms.within(atoms.C1, 2.0):
            "{} {}".format(atom, atom.ms.iso, atom.ms.aniso)

        self.assertEqual(len(atoms.species('H').ms.iso), 6)

        self.assertAlmostEqual(mean(atoms.C1.bonded.species('H').ms.iso),
                               29.9838078506)
        self.assertAlmostEqual(mean(atoms.C2.bonded.species('H').ms.iso),
                               28.7851386496)
        self.assertAlmostEqual(mean(atoms.O1.bonded.species('H').ms.iso),
                               31.9849757497)

        self.assertEqual(atoms.C1.ms.sigma.shape, (3, 3))
        self.assertEqual(len(atoms.C1.ms.evecs), 3)
        self.assertEqual(len(atoms.C1.ms.evals), 3)
예제 #3
0
    def test_efg(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

        self.assertTrue(hasattr(atoms, "efg"))

        self.assertEqual(len(atoms.efg), 9)

        # Check that the EFGs are traceless
        for efg in atoms.efg:
            self.assertTrue(numpy.trace(efg.V) / 3.0 < 1e-12)

        # Check that the principal components are ordered by the Haeberlen convention
        # |Vzz| >= |Vxx| >= |Vyy|
        for efg in atoms.efg:
            self.assertTrue(abs(efg.evals[2]) >= abs(efg.evals[0]))
            self.assertTrue(abs(efg.evals[0]) >= abs(efg.evals[1]))

        # Check that eta is positive and <=1 (Cq can be positive or negative)
        # eta = (Vxx - Vyy)/Vzz, 0 <= eta <= 1
        for efg in atoms.efg:
            self.assertTrue((efg.evals[1] - efg.evals[0]) / efg.evals[2] >= 0)
            self.assertTrue((efg.evals[1] - efg.evals[0]) / efg.evals[2] <= 1)
            self.assertTrue(efg.eta >= 0)
            self.assertTrue(efg.eta <= 1)
예제 #4
0
    def test(self):
        from magres.atoms import MagresAtoms

        atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, 'ethanol-all.magres'))

        self.assertEqual(len(atoms), 9)

        for atom in atoms:
            "{} {}".format(atom, atom.ms.iso)

        atoms.species('H').set_reference(10.0)

        for atom in atoms.species('H'):
            "{} {}".format(atom, atom.ms.cs)

        for atom in atoms.within(atoms.C1, 2.0):
            "{} {}".format(atom, atom.ms.iso, atom.ms.aniso)

        self.assertEqual(len(atoms.species('H').ms.iso), 6)

        self.assertAlmostEqual(mean(atoms.C1.bonded.species('H').ms.iso), 29.9838078506)
        self.assertAlmostEqual(mean(atoms.C2.bonded.species('H').ms.iso), 28.7851386496)
        self.assertAlmostEqual(mean(atoms.O1.bonded.species('H').ms.iso), 31.9849757497)

        self.assertEqual(atoms.C1.ms.sigma.shape, (3, 3))
        self.assertEqual(len(atoms.C1.ms.evecs), 3)
        self.assertEqual(len(atoms.C1.ms.evals), 3)
예제 #5
0
    def test_labels(self):
        atoms = MagresAtoms.load_magres(self.species)

        self.assertEquals(len(atoms), 3)
        self.assertEquals(len(atoms.label('H')), 1)
        self.assertEquals(len(atoms.label('C')), 0)
        self.assertEquals(len(atoms.label('C1')), 1)
        self.assertEquals(len(atoms.label('C2')), 1)
예제 #6
0
  def test_labels(self):
    atoms = MagresAtoms.load_magres(self.species)

    self.assertEquals(len(atoms), 3)
    self.assertEquals(len(atoms.label('H')), 1)
    self.assertEquals(len(atoms.label('C')), 0)
    self.assertEquals(len(atoms.label('C1')), 1)
    self.assertEquals(len(atoms.label('C2')), 1)
예제 #7
0
 def test_angles(self):
   atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "angles/angles1.magres"))
   
   self.assertTrue(allclose(atoms.angle(atoms.C1, atoms.C2, atoms.C4, degrees=True), 45.0))
   self.assertTrue(allclose(atoms.angle(atoms.C1, atoms.C2, atoms.C6, degrees=True), 90.0))
   
   self.assertTrue(allclose(atoms.angle(atoms.C2, atoms.C1, atoms.C4), math.pi/2.0))
   self.assertTrue(allclose(atoms.angle(atoms.C2, atoms.C1, atoms.C6), math.pi/4.0))
예제 #8
0
    def test_nmr(self):
        """
          Check that the magnetic shielding tensors are being loaded.
        """
        atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

        self.assertTrue(hasattr(atoms, "ms"))

        self.assertEqual(len(atoms.ms), 9)
예제 #9
0
    def test_angles_boundary(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "angles/angles1.magres"))

        self.assertTrue(
            allclose(atoms.angle(atoms.C2, atoms.C1, atoms.C3, degrees=True),
                     180.0))
        self.assertTrue(
            allclose(atoms.angle(atoms.C6, atoms.C1, atoms.C9, degrees=True),
                     90.0))
예제 #10
0
    def test_dihedral5(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "angles/dihedral5.magres"))

        self.assertTrue(
            allclose(
                atoms.dihedral(atoms.C1,
                               atoms.C2,
                               atoms.C3,
                               atoms.C4,
                               degrees=True), 45.0))
예제 #11
0
  def test_replace_isc(self):
    atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol-isc.magres"))

    atoms.C2.isc[0].K

    with self.assertRaises(Exception):
      atoms.C2.isc[0].K = numpy.array([1,2,3])

    orig_iso = atoms.C2.isc[0].K_iso
    new_K = atoms.C2.isc[0].K * 2.0

    atoms.C2.isc[0].K = new_K
    
    self.assertEqual(atoms.C2.isc[0].K_iso, orig_iso * 2.0)
예제 #12
0
    def test_angles(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "angles/angles1.magres"))

        self.assertTrue(
            allclose(atoms.angle(atoms.C1, atoms.C2, atoms.C4, degrees=True),
                     45.0))
        self.assertTrue(
            allclose(atoms.angle(atoms.C1, atoms.C2, atoms.C6, degrees=True),
                     90.0))

        self.assertTrue(
            allclose(atoms.angle(atoms.C2, atoms.C1, atoms.C4), math.pi / 2.0))
        self.assertTrue(
            allclose(atoms.angle(atoms.C2, atoms.C1, atoms.C6), math.pi / 4.0))
예제 #13
0
    def test_replace_isc(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "ethanol-isc.magres"))

        atoms.C2.isc[0].K

        with self.assertRaises(Exception):
            atoms.C2.isc[0].K = numpy.array([1, 2, 3])

        orig_iso = atoms.C2.isc[0].K_iso
        new_K = atoms.C2.isc[0].K * 2.0

        atoms.C2.isc[0].K = new_K

        self.assertEqual(atoms.C2.isc[0].K_iso, orig_iso * 2.0)
예제 #14
0
  def test_full_isc(self):
    magres_files = [MagresFile(open(os.path.join(DATA_DIR, "ethanol", f))) for f in os.listdir(os.path.join(DATA_DIR, "ethanol")) if f.startswith('ethanol-jc')]

    self.assertEqual(len(magres_files), 9)

    atoms = MagresAtoms.load_magres(magres_files)

    for atom in atoms:
      self.assertTrue(hasattr(atom, "isc"))

    self.assertEqual(len(atoms.isc), len(atoms) * (len(atoms) - 1))

    # Check every atom has couplings to every other atom
    for atom in atoms:
      self.assertEqual(len(atom.isc), len(atoms)-1)
예제 #15
0
  def test_efg(self):
    atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))
    
    self.assertTrue(hasattr(atoms, "efg"))

    self.assertEqual(len(atoms.efg), 9)

    # Check that the EFGs are traceless
    for efg in atoms.efg:
      self.assertTrue(numpy.trace(efg.V)/3.0 < 1e-12)

    # Check that the principal components are ordered by the Haeberlen convention
    # |Vzz| >= |Vxx| >= |Vyy|
    for efg in atoms.efg:
      self.assertTrue(abs(efg.evals[2]) >= abs(efg.evals[0]))
      self.assertTrue(abs(efg.evals[0]) >= abs(efg.evals[1]))
예제 #16
0
  def test_replace_efg(self):
    """
      Check that we can replace the tensor on an atom.
    """

    atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

    with self.assertRaises(Exception):
      atoms.C1.efg.V = numpy.array([1,2,3])

    orig_Cq = atoms.C1.efg.Cq
    new_V = atoms.C1.efg.V * 2.0

    atoms.C1.efg.V = new_V
    
    self.assertEqual(atoms.C1.efg.Cq, orig_Cq * 2.0)
예제 #17
0
    def test_replace_nmr(self):
        """
          Check that we can replace the tensor on an atom.
        """

        atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

        with self.assertRaises(Exception):
            atoms.C1.ms.sigma = numpy.array([1, 2, 3])

        orig_iso = atoms.C1.ms.iso
        new_sigma = atoms.C1.ms.sigma * 2.0

        atoms.C1.ms.sigma = new_sigma

        self.assertEqual(atoms.C1.ms.iso, orig_iso * 2.0)
예제 #18
0
    def test_within_orthorhombic(self):
        atoms = MagresAtoms.load_magres(self.orthorhombic)

        self.assertEqual(len(atoms), 1)

        p = atoms[0].position

        self.assertEqual(len(atoms.within(p, 1.0)), 3)

        num_within_3 = 0
        for atom in atoms.within(p, 10.0):
            if atom.dist(atoms[0]) <= 3.0:
                num_within_3 += 1

        self.assertEqual(len(atoms.within(p, 3.0)), num_within_3)
        self.assertEqual(len(atoms.within(p, 5.0).within(p, 2.0)), len(atoms.within(p, 2.0).within(p, 5.0)))
예제 #19
0
    def test_within_orthorhombic(self):
        atoms = MagresAtoms.load_magres(self.orthorhombic)

        self.assertEquals(len(atoms), 1)

        p = atoms[0].position

        self.assertEquals(len(atoms.within(p, 1.0)), 3)

        num_within_3 = 0
        for atom in atoms.within(p, 10.0):
            if atom.dist(atoms[0]) <= 3.0:
                num_within_3 += 1

        self.assertEquals(len(atoms.within(p, 3.0)), num_within_3)
        self.assertEquals(len(atoms.within(p, 5.0).within(p, 2.0)),
                          len(atoms.within(p, 2.0).within(p, 5.0)))
예제 #20
0
    def test_replace_efg(self):
        """
          Check that we can replace the tensor on an atom.
        """

        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

        with self.assertRaises(Exception):
            atoms.C1.efg.V = numpy.array([1, 2, 3])

        orig_Cq = atoms.C1.efg.Cq
        new_V = atoms.C1.efg.V * 2.0

        atoms.C1.efg.V = new_V

        self.assertEqual(atoms.C1.efg.Cq, orig_Cq * 2.0)
예제 #21
0
    def test_nmr(self):
        atoms = MagresAtoms.load_magres(
            os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

        self.assertTrue(hasattr(atoms, "ms"))
        self.assertTrue(hasattr(atoms, "efg"))

        self.assertEqual(len(atoms.efg), 9)
        self.assertEqual(len(atoms.ms), 9)

        # Check that the EFGs are traceless
        for efg in atoms.efg:
            self.assertTrue(numpy.trace(efg.V) / 3.0 < 1e-12)

        # Check that the principal components are ordered by the Haeberlen convention
        # |Vzz| >= |Vxx| >= |Vyy|
        for efg in atoms.efg:
            self.assertTrue(abs(efg.evals[2]) >= abs(efg.evals[0]))
            self.assertTrue(abs(efg.evals[0]) >= abs(efg.evals[1]))
예제 #22
0
    def test_full_isc(self):
        magres_files = [
            MagresFile(open(os.path.join(DATA_DIR, "ethanol", f)))
            for f in os.listdir(os.path.join(DATA_DIR, "ethanol"))
            if f.startswith('ethanol-jc')
        ]

        self.assertEqual(len(magres_files), 9)

        atoms = MagresAtoms.load_magres(magres_files)

        for atom in atoms:
            self.assertTrue(hasattr(atom, "isc"))

        self.assertEqual(len(atoms.isc), len(atoms) * (len(atoms) - 1))

        # Check every atom has couplings to every other atom
        for atom in atoms:
            self.assertEqual(len(atom.isc), len(atoms) - 1)
예제 #23
0
  def test_isc(self):
    atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol-isc.magres"))

    self.assertTrue(hasattr(atoms.C2, "isc"))
    self.assertTrue(hasattr(atoms.C2, "isc_orbital_p"))
    self.assertTrue(hasattr(atoms.C2, "isc_orbital_d"))
    self.assertTrue(hasattr(atoms.C2, "isc_spin"))
    self.assertTrue(hasattr(atoms.C2, "isc_fc"))

    self.assertEqual(len(atoms.C2.isc), len(atoms)-1)

    perturb_atom = atoms.get('C', 2)

    for isc in atoms.C2.isc:
      self.assertEqual(isc.atom1, perturb_atom)
      self.assertEqual(isc.K_iso, numpy.trace(isc.K)/3.0)
    
    # Check that the principal components are ordered by the Haeberlen convention
    for isc in atoms.C2.isc:
      self.assertTrue(abs(isc.K_evals[2] - isc.K_iso) >= abs(isc.K_evals[0] - isc.K_iso))
      self.assertTrue(abs(isc.K_evals[0] - isc.K_iso) >= abs(isc.K_evals[1] - isc.K_iso))
예제 #24
0
    def test_efg(self):
        atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "ethanol/ethanol-nmr.magres"))

        self.assertTrue(hasattr(atoms, "efg"))

        self.assertEqual(len(atoms.efg), 9)

        # Check that the EFGs are traceless
        for efg in atoms.efg:
            self.assertTrue(numpy.trace(efg.V) / 3.0 < 1e-12)

        # Check that the principal components are ordered by the Haeberlen convention
        # |Vzz| >= |Vxx| >= |Vyy|
        for efg in atoms.efg:
            self.assertTrue(abs(efg.evals[2]) >= abs(efg.evals[0]))
            self.assertTrue(abs(efg.evals[0]) >= abs(efg.evals[1]))

        # Check that eta is positive and <=1 (Cq can be positive or negative)
        # eta = (Vxx - Vyy)/Vzz, 0 <= eta <= 1
        for efg in atoms.efg:
            self.assertTrue((efg.evals[1] - efg.evals[0]) / efg.evals[2] >= 0)
            self.assertTrue((efg.evals[1] - efg.evals[0]) / efg.evals[2] <= 1)
            self.assertTrue(efg.eta >= 0)
            self.assertTrue(efg.eta <= 1)
예제 #25
0
for f in find_all_magres(sys.argv[1]):
  try:
    magres_files.append(MagresFile(f))
  except BadVersion:
    continue

s1 = sys.argv[2]
i1 = int(sys.argv[3])
s2 = sys.argv[4]
i2 = int(sys.argv[5])

tensor = 'isc'
if len(sys.argv) >= 7:
  tensor = sys.argv[6]

atoms = MagresAtoms.load_magres(magres_files)

atom1 = atoms.get_species(s1, i1)
atom2 = atoms.get_species(s2, i2)

if tensor == "isc_spin_total":
  K1 = atom1.isc_fc[atom2].K + atom1.isc_spin[atom2].K
  K2 = atom2.isc_fc[atom1].K + atom2.isc_spin[atom1].K
else:
  K1 = getattr(atom1, tensor)[atom2].K
  K2 = getattr(atom2, tensor)[atom1].K


#K1 = getattr(atom1, tensor)[atom2].K
#K2 = getattr(atom2, tensor)[atom1].K
예제 #26
0
atoms_filter_str = a.atoms

if atoms_filter_str:
  atoms_filter = parse_atom_list(atoms_filter_str)
else:
  atoms_filter = lambda x: True

tensors = ['ms']

lines = []

print "# Number\tAtom\tIso\tAniso\tAsym\tPath"

if os.path.isfile(a.source_dir):
  magres_atoms = [MagresAtoms.load_magres(a.source_dir)]
else:
  magres_atoms = load_all_magres(a.source_dir)

isos = {}

for iso_ in a.iso:
  num = re.findall('([0-9]+)', iso_)[0]
  sym = re.findall('([A-Za-z]+)', iso_)[0]

  isos[sym] = int(num)

for i, atoms in enumerate(magres_atoms):
  num = get_numeric(atoms.magres_file.path)

  for s, iso in isos.items():
예제 #27
0
# -*- coding: utf-8 -*-

# =============================================================================
# Copyright (C) 2015 Christian Fernandez
# Laboratoire Catalyse et Spectrochimie, Caen, France.
# [email protected]
#
# This software is governed by the CeCILL-B license under French law
# and abiding by the rules of distribution of free software.
# You can  use, modify and/ or redistribute the software under
# the terms of the CeCILL-B license as circulated by CEA, CNRS and INRIA
# at the following URL "http://www.cecill.info".
#
# See Licence.txt in the main directory
# =============================================================================

"""Short description.

A longer description.

"""

from __future__ import print_function

from magres.atoms import MagresAtoms, MagresAtomsView
ethanol_atoms = MagresAtoms.load_magres('../samples/ethanol-all.magres')

ethanol_atoms.calculate_bonds()
예제 #28
0
else:
    atoms_filter = lambda x: True

tensors = [
    'efg',
]  # 'efg_local', 'efg_nonlocal']

lines = []

if a.numbers:
    print("# Number\tAtom\tCq\tEta\tPath")
else:
    print("# Atom\tCq\tEta\tPath")

if os.path.isfile(a.source):
    magres_atoms = [MagresAtoms.load_magres(a.source)]
else:
    magres_atoms = load_all_magres(a.source)

for i, atoms in enumerate(magres_atoms):
    num = get_numeric(atoms.magres_file.path)

    if num:
        idx = num
    else:
        idx = [i]

    for atom in atoms:
        if atoms_filter(atom) and \
                hasattr(atom, 'efg'):
예제 #29
0
"""
Script for extracting NMR shielding values 
from .magres files generated by CASTEP

Generates line plot of all shifts

Comment out H or C as necessary
"""
from magres.atoms import MagresAtoms
import matplotlib.pyplot as plt
import numpy as np
import csv

atoms = MagresAtoms.load_magres(
    './spectra_processing/1,2-dichlorobenzene/free/12_dichlorobenzene_free.magres'
)  #add path to magres file
nucleus = 'h'
save_csv = './spectra_processing/1,2-dichlorobenzene/free/H_shifts.csv'

shifts = []
shift_labels = []

# Extracts Atoms
C = atoms.species('C')
#I = np.linspace(1, 1, len(C))

H = atoms.species('H')
#I = np.linspace(1, 1, len(H))

# Extracts isotopic magnetic shielding and references shifts
for atom in H:
예제 #30
0
import sys
import math
import numpy
from magres.atoms import MagresAtoms

# Load T1Si0.magres sample into an atoms structure
atoms = MagresAtoms.load_magres("samples/T1Si0.magres")

atomAl15 = atoms.get_species('Al', 15)

for atom in atoms.species('Al'):
  if atom == atomAl15:
    continue

  Vzz = atom.efg.evecs[2]
  dr = atom.position - atomAl15.position

  Vzz_dr_ang = math.acos(numpy.dot(Vzz, dr) / math.sqrt(numpy.dot(dr,dr) * numpy.dot(Vzz,Vzz)))

  print atom, atom.efg.Cq, Vzz_dr_ang

예제 #31
0
from __future__ import print_function
import sys
from magres.atoms import MagresAtoms

# Load ethanol-jc.magres sample into an atoms structure
atoms = MagresAtoms.load_magres("../samples/ethanol-jc.magres")

# For fun, set all the hydrogens to be tritium
for atom in atoms.species('H'):
    atom.isotope = 3

# Set all the carbons to be 12C (won't work!)
try:
    for atom in atoms.species('C'):
        atom.isotope = 12
except ValueError as e:
    print("Error changing C isotopes:", e, file=sys.stderr)

# Loop over and print out coupling symbol, distance between atoms, isotropic coupling, anisotropic coupling and
# asymmetry
for isc in atoms.isc:
    print(isc.atom1, isc.atom2, isc.dist, isc.J_iso, isc.J_aniso, isc.J_eta)
예제 #32
0
 def test_angles_boundary(self):
   atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "angles/angles1.magres"))
   
   self.assertTrue(allclose(atoms.angle(atoms.C2, atoms.C1, atoms.C3, degrees=True), 180.0))
   self.assertTrue(allclose(atoms.angle(atoms.C6, atoms.C1, atoms.C9, degrees=True), 90.0))
예제 #33
0
#!python
from __future__ import print_function
import sys
from numpy import mean
from magres.atoms import MagresAtoms

# Load the magres files
out_atoms = MagresAtoms.load_magres(sys.argv[1])
atomss = [MagresAtoms.load_magres(f) for f in sys.argv[1:]]

for atom in out_atoms:
    other_atoms = [atoms.species(atom.species)[atom.index - 1] for atoms in atomss]

    atom.magres_atom['position'] = mean([atom_.position for atom_ in other_atoms], 0).tolist()

    if hasattr(atom, 'ms'):
        atom.ms.magres_ms['sigma'] = mean([atom_.ms.sigma for atom_ in other_atoms], 0).tolist()

    if hasattr(atom, 'efg'):
        atom.efg.magres_efg['V'] = mean([atom_.efg.V for atom_ in other_atoms], 0).tolist()

print(out_atoms.magres_file)
예제 #34
0
 def test_labels(self):
     atoms = MagresAtoms.load_magres(self.species)
예제 #35
0
  def test_dihedral5(self):
    atoms = MagresAtoms.load_magres(os.path.join(DATA_DIR, "angles/dihedral5.magres"))

    self.assertTrue(allclose(atoms.dihedral(atoms.C1, atoms.C2, atoms.C3, atoms.C4, degrees=True), 45.0))
예제 #36
0
 def test_labels(self):
     atoms = MagresAtoms.load_magres(self.species)
예제 #37
0
    def test_species(self):
        atoms = MagresAtoms.load_magres(self.species)

        self.assertEqual(len(atoms), 3)
        self.assertEqual(len(atoms.species("H")), 1)
        self.assertEqual(len(atoms.species("C")), 2)
예제 #38
0
#!python
from __future__ import print_function
import sys
from numpy import mean
from magres.atoms import MagresAtoms

# Load the magres files
out_atoms = MagresAtoms.load_magres(sys.argv[1])
atomss = [MagresAtoms.load_magres(f) for f in sys.argv[1:]]

for atom in out_atoms:
    other_atoms = [
        atoms.species(atom.species)[atom.index - 1] for atoms in atomss
    ]

    atom.magres_atom['position'] = mean(
        [atom_.position for atom_ in other_atoms], 0).tolist()

    if hasattr(atom, 'ms'):
        atom.ms.magres_ms['sigma'] = mean(
            [atom_.ms.sigma for atom_ in other_atoms], 0).tolist()

    if hasattr(atom, 'efg'):
        atom.efg.magres_efg['V'] = mean([atom_.efg.V for atom_ in other_atoms],
                                        0).tolist()

print(out_atoms.magres_file)
예제 #39
0
from magres.atoms import MagresAtoms

atoms = MagresAtoms.load_magres('samples/simple.magres')

print atoms[0].position

Catoms = atoms.species('C')

print "1"
for atom in Catoms.within(atoms[0], 1.0):
  print atom, atom.position

print "5"
for atom in Catoms.within(atoms[0], 3.0):
  print atom, atom.position

print "5-1"
for atom in Catoms.within(atoms[0], 3.0).within(atoms[0], 1.0):
  print atom, atom.position

print "1-5"
for atom in Catoms.within(atoms[0], 1.0).within(atoms[0], 3.0):
  print atom, atom.position


예제 #40
0
  def test_species(self):
    atoms = MagresAtoms.load_magres(self.species)

    self.assertEquals(len(atoms), 3)
    self.assertEquals(len(atoms.species('H')), 1)
    self.assertEquals(len(atoms.species('C')), 2)
예제 #41
0
from __future__ import print_function
import sys
import math
import numpy
from magres.atoms import MagresAtoms

# Load T1Si0.magres sample into an atoms structure
atoms = MagresAtoms.load_magres("../samples/T1Si0.magres")

atomAl15 = atoms.get("Al", 15)

for atom in atoms.species("Al"):
    if atom == atomAl15:
        continue

    Vzz = atom.efg.evecs[2]
    dr = atom.position - atomAl15.position

    Vzz_dr_ang = math.acos(numpy.dot(Vzz, dr) / math.sqrt(numpy.dot(dr, dr) * numpy.dot(Vzz, Vzz)))

    print(atom, atom.efg.Cq, Vzz_dr_ang)
예제 #42
0
import sys
from magres.atoms import MagresAtoms

atoms = MagresAtoms.load_magres("samples/ethanol-nmr.magres")

for atom in atoms:
  print atom, atom.ms.iso, atom.ms.aniso, atom.ms.zeta, atom.ms.eta, atom.ms.span, atom.ms.skew, atom.ms.evals[0], atom.ms.evals[1], atom.ms.evals[2]

예제 #43
0
from __future__ import print_function
from magres.atoms import MagresAtoms

atoms = MagresAtoms.load_magres('../samples/simple.magres')

print(atoms[0].position)

Catoms = atoms.species('C')

print("1")
for atom in Catoms.within(atoms[0], 1.0):
    print(atom, atom.position)

print("5")
for atom in Catoms.within(atoms[0], 3.0):
    print(atom, atom.position)

print("5-1")
for atom in Catoms.within(atoms[0], 3.0).within(atoms[0], 1.0):
    print(atom, atom.position)

print("1-5")
for atom in Catoms.within(atoms[0], 1.0).within(atoms[0], 3.0):
    print(atom, atom.position)
예제 #44
0
#!python
import sys
from magres.atoms import MagresAtoms

file = sys.argv[1]
atoms = MagresAtoms.load_magres(file)

print "# Principle components of sigma (magnetic shielding, unreferenced) tensor"

for atom in atoms:
    pcs = atom.ms.evals
    print ", ".join(
        map(str, [atom.species, atom.index, pcs[0], pcs[1], pcs[2]]))
import sys
from magres.format import MagresFile
from magres.utils import find_all_magres
from magres.atoms import MagresAtoms

magres_files = [MagresFile(f) for f in find_all_magres(sys.argv[1])]

atoms = MagresAtoms.load_magres(magres_files)

coupling_atom = atoms.get_species('C', 1)

# Set a bunch of arbitrary references for the magnetic shielding
atoms.set_reference('H', 100.0)
atoms.set_reference('C', 55.0)
atoms.set_reference('O', -2.0)

for atom in atoms:
  print atom, atom.efg.Cq, atom.ms.iso, atom.isc[coupling_atom].J_iso

예제 #46
0
    def test_species(self):
        atoms = MagresAtoms.load_magres(self.species)

        self.assertEquals(len(atoms), 3)
        self.assertEquals(len(atoms.species('H')), 1)
        self.assertEquals(len(atoms.species('C')), 2)