Пример #1
0
 def get_atomization_energies(self, prog, meth):
     """ get AE """
     udct = {'h': io2.Units().h2kc}
     const = 1.0
     if meth in ['a', 'all']:
         meths = list(self.props.keys())
     else:
         meths = [meth]
     aes = {}
     for mt in meths:
         _es0 = np.zeros(1 + self.zsu[-1])
         for zi in self.zsu:
             si = chemical_symbols[zi]
             #try:
             ei0 = cda.dct[prog][si][mt]
             #print('ei0=',ei0)
             #except:
             #    ei0 = cda.dct[prog][mt][si]
             _es0[zi] = ei0 * udct['h']
         _aes = []
         for i, na in enumerate(self.nas):
             ib, ie = self.ias1[i], self.ias2[i]
             zsi = self.zs[ib:ie]
             ei0 = np.sum([_es0[zsi]])
             #print('props=', self.props)
             _aes.append(self.props[mt][i] * const - ei0)
         aes[mt] = np.array(_aes)
         #self.props[mt] = np.array(aes)
     self.aes = aes
Пример #2
0
 def __init__(self, fs, pns=None, unit='h'):
     nas = []
     zs = []
     coords = []
     nsheav = []
     props = {}
     self.nm = len(fs)
     const = 1.
     if unit in ['h']: const = io2.Units().h2kc
     for f in fs:
         _nas, _zs, _coords, _nsheav, _props = read_xyz_simple(
             f, opt='z', property_names=pns)
         #print('f,props=',f, _props)
         nas += list(_nas)
         zs += list(_zs)
         coords += list(_coords)
         nsheav += list(_nsheav)
         for k in _props:
             if k in props:
                 props[k] += [_props[k] * const]
             else:
                 props[k] = [_props[k] * const]
     self.nas = nas
     self.zs = zs
     self.coords = coords
     self.nsheav = nsheav
     self.props = props
     self.ias2 = np.cumsum(nas)
     self.ias1 = np.concatenate(([0], self.ias2[:-1]))
Пример #3
0
 def __init__(self, es, basis, unit='h'): #, etype='corr'):
     """
     Note: input energy (`es) has to be either HF energies or other type of energies
     """
     self.es = es
     self.basis = basis
     uc = io2.Units()
     self.const = {'kcal':uc.h2kc, 'h':1.0}[unit]
Пример #4
0
    def calc_ae_dressed(self, idx1, idx2=None, meth=None, ref=None):
        """
        calc dressed atom or/and bond energies as baseline

        vars
        ====================
        ref: if set to None, then E_atom will be regressed by input mols
             otherwise, E_atom will be regressed from a set of small mols
             located in folder `ref/ (i.e., h2,ch4,n2,o2,f2,s8,p4,cl2,br2,i2)
        """
        ims = np.arange(self.nm)
        if isinstance(idx1, int):
            idx1 = ims[:idx1]
        if idx2:
            if isinstance(idx2, int):
                idx2 = ims[idx2:]
        else:
            idx2 = np.setdiff1d(ims, idx1)
        if meth is None:
            meths = list(self.props.keys())
            if len(meths) > 1:
                raise Exception(
                    '#ERROR: multiple property avail. Please specify one!')
            meth = meths[0]
        ns1, ns2 = self.ngs[idx1], self.ngs[idx2]
        nel = len(ns1[0])
        uc = io2.Units()
        const = 1.0  #{'h': uc.h2kc, 'kcal':1.0 }[iu]
        if hasattr(self, 'ys'):
            ys = self.ys
        else:
            ys = self.props[meth]
        ys *= const
        ys1, ys2 = ys[idx1], ys[idx2]
        istat = T
        if ref is None:  # default case
            esb, _, rank, _ = np.linalg.lstsq(ns1, ys1, rcond=None)
            if rank < nel:
                print(' ** number of molecules .le. number of elements')
                esb = np.zeros(nel)
                istat = F
        else:
            esb = get_reference_atomic_energy(ref, meth, self.zsu)
        ys1p = np.dot(ns1, esb)
        #print ' +++++ ys1.shape, ys1p.shape = ', ys1.shape, ys1p.shape
        dys1 = ys1 - ys1p
        ys2_base = np.dot(ns2, esb)
        dys2 = ys2 - ys2_base
        return istat, dys1, dys2, ys2_base
Пример #5
0
 def get_force(self):
     iou = io2.Units()
     const = iou.h2e / iou.b2a  # from hartree/bohr to eV/A
     #cmd = "grep '^\s*[XYZ][0-9]*   ' %s | awk '{print $3}'"%self.f #
     cmd1 = "awk '/^ Variable       Old X    -DE/{print NR}' %s | tail -1" % self.f
     Ln1 = int(io2.cmdout2(cmd1)) + 2
     cmd2 = "awk '/^         Item               Value     Threshold  Converged/{print NR}' %s | tail -1" % self.f
     Ln2 = int(io2.cmdout2(cmd2)) - 1
     cmd = "sed -n '%d,%dp' %s" % (Ln1, Ln2, self.f)
     #print cmd
     cs = io2.cmdout2(cmd).split('\n')
     vals = [eval(ci.split()[2]) for ci in cs]
     #print vals
     #print len(vals)
     forces = np.array(vals).reshape((self.na, 3)) * const
     #abs_forces = np.linalg.norm( forces, axis=1 )
     #self.forces = abs_forces[:, np.newaxis]
     return forces
Пример #6
0
def obj2m(obj, property_names=None, isimple=F, idx=None, unit=None):
    assert unit is not None

    if property_names:
        if ('nmr' in property_names) or ('chgs' in property_names):
            isimple = T

    if isinstance(obj, str):
        if (not os.path.isfile(obj)):
            raise Exception('#ERROR: file does not exist')
        if (obj[-3:] == 'xyz'):
            func = read_xyz_simple if (isimple and (idx is None)) else read_xyz
            nas, zs, coords, nsheav, props = func(
                obj, property_names=property_names, idx=idx)
        elif (obj[-3:] == 'sdf'):
            property_names = []
            _mi = read_sdf(obj, iconn=F)
            nas = [len(_mi)]
            zs = _mi.numbers
            coords = _mi.positions
            nsheav = [(zs > 1).sum()]
            props = {}
        else:
            raise Exception('#ERROR: non-xyz file')
    elif isinstance(obj, list):
        nas = []
        zs = []
        coords = []
        nsheav = []
        props = {}
        for _obj in obj:
            #print('type(obj)=',type(obj))
            if (_obj[-3:] == 'xyz'):
                func = read_xyz_simple if (isimple and
                                           (idx is None)) else read_xyz
                _nas, _zs, _coords, _nsheav, _props = func(
                    _obj, property_names=property_names, idx=idx)
            elif (_obj[-3:] == 'sdf'):
                property_names = []
                _mi = read_sdf(_obj, iconn=F)
                _nas = [len(_mi)]
                _zs = _mi.numbers
                _coords = _mi.positions
                _nsheav = [(_zs > 1).sum()]
                _props = {}
            else:
                raise Exception('#ERROR: not sdf/xyz file')
            zs += list(_zs)
            coords += list(_coords)
            nsheav += list(_nsheav)
            nas += list(_nas)
            #print('props=', _props)
            property_names = list(_props.keys())
            for p in property_names:
                yi = _props[p]
                if p in props.keys():
                    props[p] += [yi]
                else:
                    props[p] = [yi]
    #elif 'molecules' in obj.__str__():
    #    nas, zs, coords, nsheav, props = obj._nas, obj._zs, obj._coords, obj._nsheav, obj.props
    elif 'catoms' in obj.__str__():
        nas, zs, coords, nsheav, props = obj.nas, obj.zs, obj.coords, obj.nsheav, obj.props
    else:
        print('obj=', obj)
        raise Exception('#ERROR: unknown input `obj!')

    const = 1.0
    for p in props:
        if unit in ['h', 'ha']:
            const = io2.Units().h2kc
        v = props[p]
        if p in [
                'chg', 'chgs', 'nmr', 'cls', 'force', 'forces', 'grad',
                'grads', 'alpha'
        ]:
            const = 1.0
        props[p] = np.array(v) * const

    return nas, zs, coords, nsheav, props
Пример #7
0
#!/usr/bin/env python

import re, os, sys
import aqml.io2 as io2
import aqml.cheminfo as co
import aqml.cheminfo.core as cc
import numpy as np

T, F = True, False

uc = io2.Units()

cardinal = {'vdz': 2, 'vtz': 3, 'vqz': 4}

bsts =  ['aug-cc-pvdz', 'aug-cc-pvtz', 'aug-cc-pvqz', \
         'cc-pvdz', 'cc-pvtz', 'cc-pvqz', \
         'def2-sv(p)', 'def2-svp', 'def2-tzvp', 'def2-qzvp']
bsts_short = ['avdz', 'avtz', 'avqz', \
              'vdz', 'vtz','vqz', \
              'def2sv-p', 'def2svp', 'def2tzvp', 'def2qzvp']
dctbo = dict(zip(bsts, bsts_short))
dctbi = dict(zip(bsts_short, bsts))

hs_short = ['mp2', 'lmp2', 'lcc', 'lcc2', 'cc', 'cc2']  # Hamitonian
hs = ['RI-MP2', 'DLPNO-MP2', 'DLPNO-CCSD', 'CCSD', 'CCSD(T)']
dcthi = dict(zip(hs_short, hs))
dctho = dict(zip(hs, hs_short))

cmdout = lambda cmd: os.popen(cmd).read().strip()
cmdout1 = lambda cmd: os.popen(cmd).read().strip().split('\n')