Interface with cclibΒΆ

try pytraj online:


interface_to_cclib
In [1]:
# supposed you want to extract coordinates from Gaussian run and load to pytraj

# load cclib
import cclib

gau = cclib.parser.Gaussian('GF2.log')
gau
Out[1]:
Gaussian("GF2.log")
In [2]:
go = gau.parse()
go
Out[2]:
<cclib.parser.data.ccData_optdone_bool at 0x2aaaaaabc518>
In [3]:
go.atomcoords.shape, go.atomcoords.dtype
Out[3]:
((56, 34, 3), dtype('float64'))
In [4]:
# load to pytraj's Trajectory
# we need a pdb file (or an Amber topology file, or a PSF file or anything that pytraj/cpptraj supports)
# in this case, we only need to use an original pdb file from your Gaussian run

traj = pt.Trajectory(xyz=go.atomcoords, top='GF2.pdb')
traj
Out[4]:
<pytraj.Trajectory, 56 frames, include:
<Topology: 34 atoms, 1 residues, 1 mols, non-PBC>>
           
In [5]:
traj.xyz.shape, traj.xyz.dtype
Out[5]:
((56, 34, 3), dtype('float64'))
In [6]:
{atom.element for atom in traj.top.atoms}
Out[6]:
{'CARBON', 'FLUORINE', 'HYDROGEN', 'NITROGEN', 'OXYGEN', 'PHOSPHORUS'}
In [7]:
# get some insighful info, such as glycosidic angle vs time
chin = pt.calc_chin(traj)[0]
chin
Out[7]:
<pytraj.array.DataArray: size=56, key=chin:1, dtype=float64, ndim=1> 
values:
[-165.80586142 -165.95436532 -166.27043487 ..., -116.70662514 -116.69723609
 -116.67783373]
In [8]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'  # high resolution
import matplotlib
matplotlib.rcParams['savefig.dpi'] = 2 * matplotlib.rcParams['savefig.dpi'] # larger image

from matplotlib import pyplot as plt

plt.plot(chin)
plt.xlabel('frame number')
plt.ylabel('chi (degree)')
Out[8]:
<matplotlib.text.Text at 0x2aaad524f470>

Note: use pytraj.tools.read_gausian_output

In [9]:
# pytraj.tools.read_gaussian_output is a simple wrapper of cclib

pt.tools.read_gaussian_output('GF2.log')
Out[9]:
<pytraj.Trajectory, 56 frames, include:
<Topology: 34 atoms, 1 residues, 1 mols, non-PBC>>