~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/marat/nwchem-python/generic_atom.py

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Created on Feb 7, 2012
 
3
 
 
4
@author: marat
 
5
'''
 
6
import sys
 
7
from pdbrecord import PDBAtomRecord 
 
8
import numpy 
 
9
import math
 
10
from atom_params import *
 
11
 
 
12
class GenericAtom(object):
 
13
    '''
 
14
    classdocs
 
15
    '''
 
16
 
 
17
    def __init__(self,d):
 
18
        '''
 
19
        Constructor
 
20
        '''
 
21
        self.dct = d
 
22
 
 
23
        if d:
 
24
            if type(d) is not type({}):
 
25
                print "wrong type ", type(d)
 
26
                print "expecting", type({})
 
27
                sys.exit(1)
 
28
            else:
 
29
                self.dct  = d
 
30
        try:
 
31
            self.coord=numpy.array(self.dct.pop("coord"))
 
32
        except:
 
33
            self.coord=None
 
34
                
 
35
    @classmethod                
 
36
    def fromPDBrecord(cls,buf):
 
37
        '''
 
38
        alternative constructor from PDB record
 
39
        '''
 
40
        d=PDBAtomRecord.dct(buf)
 
41
        if d:
 
42
            return cls(d)
 
43
        return None
 
44
 
 
45
    @classmethod
 
46
    def fromXYZrecord(cls,aline):
 
47
        atomstr  = string.split(aline)[0:4]
 
48
        if len(atomstr) < 4:
 
49
            return None
 
50
            
 
51
        name = atomstr[0]
 
52
        coord=[float(x) for x  in atomstr[1:]]
 
53
        return cls({"grouptag":"XYZ", "coord":coord,"name":name})
 
54
        
 
55
    @staticmethod
 
56
    def bondlength(a1,a2):
 
57
        dr=a1.coord-a2.coord
 
58
        return numpy.linalg.norm(dr)
 
59
 
 
60
    @staticmethod
 
61
    def angle(a1,a2,a3):
 
62
        u=a1.coord-a2.coord
 
63
        v=a3.coord-a2.coord
 
64
        c = numpy.dot(u,v)/numpy.linalg.norm(u)/numpy.linalg.norm(v) 
 
65
        return  math.degrees(math.acos(c))
 
66
 
 
67
    def translate(self,v):
 
68
        self.coord=self.coord-v
 
69
            
 
70
    def covRadius(self):
 
71
        name = self.dct["name"]
 
72
        return AtomParams.covRadius(name)  
 
73
     
 
74
    def elemName(self):
 
75
        name = self.dct["name"]
 
76
        return AtomParams.elementName(name)   
 
77
 
 
78
    def name(self):
 
79
        return self.dct["name"]
 
80
    
 
81
    def res_name(self):
 
82
        '''
 
83
        '''
 
84
        return  self.dct.get("resname","UNK").strip()
 
85
                   
 
86
    def groupTag(self):
 
87
        '''
 
88
        returns that identifies group association of an atom
 
89
        based on residue name and residue id (e.g. "ASP_1")
 
90
        Default values of "UNK" and "0" are used should 
 
91
        residue name and residue id be absent
 
92
        '''
 
93
        tag = self.dct.get("grouptag")
 
94
        if tag is None:
 
95
            resname = self.dct.get("resname","UNK").strip()
 
96
            resid = str(self.dct.get("resid",0)).strip()
 
97
            tag ="_".join((resname,resid))
 
98
 
 
99
        return tag
 
100
 
 
101
    def setGroupTag(self,tag):
 
102
        '''
 
103
        returns that identifies group association of an atom
 
104
        based on residue name and residue id (e.g. "ASP_1")
 
105
        Default values of "UNK" and "0" are used should 
 
106
        residue name and residue id be absent
 
107
        '''
 
108
        self.dct["grouptag"]=tag
 
109
        
 
110
    def resTag(self):
 
111
        '''
 
112
        returns that identifies res association of an atom
 
113
        based on residue name and residue id (e.g. "ASP_1")
 
114
        '''
 
115
 
 
116
        resname = self.dct.get("resname","UNK").strip()
 
117
        resid = str(self.dct.get("resid",0)).strip()
 
118
        tag ="_".join((resname,resid))
 
119
 
 
120
        return tag    
 
121
    def setBond(self,i):
 
122
        '''
 
123
        returns that identifies group association of an atom
 
124
        based on residue name and residue id (e.g. "ASP_1")
 
125
        Default values of "UNK" and "0" are used should 
 
126
        residue name and residue id be absent
 
127
        '''
 
128
        bond = self.dct.setdefault("bond",set())
 
129
        bond.add(i)
 
130
    
 
131
        
 
132
    def __str__(self):
 
133
        return str(self.dct) + " " + str(self.coord)
 
134
 
 
135
        
 
136
    @staticmethod    
 
137
    def bonded(a1,a2):
 
138
        dr = numpy.linalg.norm(a1.coord-a2.coord)
 
139
        return dr <= (a1.covRadius()+a2.covRadius())
 
140
            
 
141
if __name__ == '__main__':
 
142
#    aline1="ATOM    588 1HG  GLU    18     -13.363  -4.163  -2.372  1.00  0.00           H"
 
143
#    aline2="ATOM      1  I1  IO3     1      -1.555  -0.350   0.333        1.39           I"
 
144
#    aline3="ATOM      2  O1  IO3     1      -0.985  -1.156   1.840       -0.80           O"
 
145
#    aline4="ATOM      2  O1                 -0.985  -1.156   1.840       -0.80           O"
 
146
#
 
147
#    a=GenericAtom.fromPDBrecord(aline2)   
 
148
#    print a.groupTag()
 
149
#    print a.coord
 
150
#    print a.dct     
 
151
#    b=GenericAtom.fromPDBrecord(aline3)
 
152
#    print b.coord
 
153
#    print b.dct         
 
154
#    print GenericAtom.bondlength(a,b),GenericAtom.bonded(a,b)
 
155
#    print a.covRadius()+b.covRadius()
 
156
#    c=GenericAtom.fromPDBrecord(aline1)
 
157
#    print GenericAtom.bondlength(a,c),GenericAtom.bonded(a,c)
 
158
#    c=GenericAtom.fromPDBrecord(aline4)    
 
159
#    print c.groupTag()
 
160
    aline6="O1                 -0.985  -1.156   1.140  0.0 0.0  "
 
161
    aline5="O1                 -0.985  -1.156   "
 
162
    d=GenericAtom.fromXYZrecord(aline6)
 
163
    d.translate([1.0,1.0,1.0])
 
164
    print d