Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ekwan/cctk
Browse files Browse the repository at this point in the history
  • Loading branch information
corinwagen committed Mar 27, 2020
2 parents 570488c + e7c5565 commit 06c0189
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ $ conda env create -f env.yml
Now, run `conda activate cctk` to enter the *cctk* Python environment (and `conda deactivate` to leave).
(More complete guides to `conda` usage can be found elsewhere.)

#### Upgrading *cctk*

To get the latest release of *cctk*, navigate to the correct `conda` environment and run:

```
$ pip install --upgrade cctk
```

To install the development version (may be unstable!), run:

```
$ pip install --upgrade [email protected]:ekwan/cctk.git@master
```

## Contents:

- `cctk/` contains the Python modules for *cctk* and the accompanying static data files.
Expand Down
14 changes: 13 additions & 1 deletion cctk/parse_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,19 @@ def read_nmr_shifts(lines, num_atoms):
Returns:
list of isotropic NMR shifts (np.ndarray)
"""
return np.zeros(shape=num_atoms)
# assumes that lines only come from one Link1 section
shieldings = []
for line in lines:
if line[14:23] == "Isotropic":
fields = line.split()
assert len(fields) == 8, f"Expected 8 fields on an NMR shielding output line but found {len(fields)} instead!"
try:
shielding = float(fields[4])
except:
raise ValueError(f"Error parsing NMR shielding output line:\n{line}")
shieldings.append(shielding)
assert len(shieldings) == num_atoms, f"Expected {num_atoms} shieldings but found {len(shieldings)}!"
return np.asarray(shieldings)

def split_link1(lines):
"""
Expand Down
38 changes: 36 additions & 2 deletions test/test_nmr.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import unittest, sys, os, io, copy, math
import numpy as np
import cctk
from cctk.gaussian_file import JobType

# run from cctk root with
# python -m unittest test.test_nmr.TestNMR
class TestNMR(unittest.TestCase):

def test_link1(self):
molecule = cctk.GaussianFile.read_file("test/static/methane2.out")
def test_nmr1(self):
# this file has a single point NMR calculation on methane
gaussian_file = cctk.GaussianFile.read_file("test/static/methane.out")
ensemble = gaussian_file.molecules
molecule = ensemble[-1]
self.assertListEqual(list(molecule.nmr_isotropic), [198.2259, 32.6869, 32.6869, 32.6869, 32.6869])

def test_nmr2(self):
# this file contains opt freq followed by Link1 NMR on methane
gaussian_file = cctk.GaussianFile.read_file("test/static/methane2.out")
self.assertEqual(len(gaussian_file), 2)
first_link = gaussian_file[0]
self.assertListEqual(first_link.job_types, [JobType.OPT, JobType.FREQ])
second_link = gaussian_file[1]
ensemble = second_link.molecules
molecule = ensemble[-1]
self.assertListEqual(list(molecule.nmr_isotropic), [192.9242, 31.8851, 31.8851, 31.8851, 31.8851])

def test_nmr3(self):
# this file contains opt freq / Link1 NMR on ethane then Link1 single point NMR on methane
gaussian_file = cctk.GaussianFile.read_file("test/static/ethane.out")
self.assertEqual(len(gaussian_file), 3)
first_link = gaussian_file[0]
self.assertListEqual(first_link.job_types, [JobType.OPT, JobType.FREQ])
second_link = gaussian_file[1]
self.assertListEqual(second_link.job_types, [JobType.NMR])
ensemble = second_link.molecules
molecule = ensemble[-1]
self.assertListEqual(list(molecule.nmr_isotropic), [180.3673, 31.2068, 31.207, 31.2068, 180.3673, 31.2068, 31.207, 31.2068])
third_link = gaussian_file[2]
self.assertListEqual(third_link.job_types, [JobType.NMR])
ensemble = third_link.molecules
molecule = ensemble[-1]
self.assertListEqual(list(molecule.nmr_isotropic), [198.2259, 32.6869, 32.6869, 32.6869, 32.6869])

'''
def load_molecule(self, path="test/static/LSD_custom.out"):
Expand Down

0 comments on commit 06c0189

Please sign in to comment.