~ubuntu-branches/ubuntu/utopic/nwchem/utopic

« back to all changes in this revision

Viewing changes to contrib/marat/nwchem-python/pdbrecord.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
    
 
7
class PDBAtomRecord(object):
 
8
    '''
 
9
    Class PDBAtomRecord processes ATOM or HETATM line in PDB file.
 
10
    For all other records None value will be returned.
 
11
    PDBAtomRecord.test is used to verify PDB line is of ATOM or HETATM type.
 
12
    PDBAtomRecord.dct will return all available records in a dictionary with the keys 
 
13
    indicated below
 
14
    '''
 
15
#   Dictionary for column locations (see at the end for more info)
 
16
    irec=dict(record=[0,6],atomid=[6,11],name=[12,16],resname=[17,20],
 
17
              resid=[22,26],coord=[30,54],element=[76,78])
 
18
#   Dictionary for types of fields
 
19
    atype=dict(record="string",atomid="int",name="string",resname="string",
 
20
               resid="int",coord="float array",element="string")
 
21
 
 
22
#    def __init__(self):
 
23
#        '''
 
24
#        Constructor
 
25
#        '''
 
26
#        pass
 
27
 
 
28
    
 
29
    @staticmethod
 
30
    def field(name,buf):
 
31
        '''
 
32
        returns value of the "name" field in the provided "buf" buffer
 
33
        always returns None value if buffer is not of ATOM or HETATM type
 
34
        '''
 
35
#        print inspect.getsource(PDBAtomRecord.fieldName)   
 
36
        if not PDBAtomRecord.test(buf):
 
37
            return None     
 
38
        ir=PDBAtomRecord.irec[name]
 
39
        atype=PDBAtomRecord.atype[name]
 
40
        value = buf[ir[0]:ir[1]]
 
41
        if value.strip()=='':
 
42
            return None
 
43
        if atype=='int':
 
44
            try:
 
45
                value = int(value)
 
46
            except:
 
47
                value = None
 
48
        elif atype=='float':
 
49
            try:
 
50
                value = float(value)
 
51
            except:
 
52
                value = None
 
53
        elif atype=='string':
 
54
            pass
 
55
        elif atype=='float array':
 
56
            try:
 
57
                value = [float(x) for x  in value.split()]
 
58
            except:
 
59
                value = None
 
60
        else:
 
61
            raise ValueError("unknown type definition")
 
62
                                
 
63
        return value 
 
64
    
 
65
    @staticmethod
 
66
    def dct(buf):
 
67
        '''
 
68
        returns all the available fields in a dictionary
 
69
        '''
 
70
        if not PDBAtomRecord.test(buf):
 
71
            return None
 
72
        
 
73
        d={}
 
74
        for name in PDBAtomRecord.irec.iterkeys():
 
75
            value=PDBAtomRecord.field(name,buf)
 
76
            if value!=None:
 
77
                d[name]=value
 
78
 
 
79
        return d   
 
80
   
 
81
    @staticmethod     
 
82
    def test(buf):
 
83
        '''
 
84
        tests whether buffer is of ATOM or HETATM type
 
85
        '''
 
86
        return buf[0:6] in ("ATOM  ","HETATM")
 
87
    
 
88
 
 
89
if __name__ == '__main__':
 
90
    aline1="ATOM    588 1HG  GLU    18     -13.363  -4.163  -2.372  1.00  0.00           H"
 
91
    aline2="ATOM    588      GLU           -13.363  -4.163  -2.372  1.00  0.00"
 
92
    aline3="ATTM    588      GLU           -13.363  -4.163  -2.372  1.00  0.00"
 
93
    
 
94
    print PDBAtomRecord.field("name",'') 
 
95
    print PDBAtomRecord.field("name",aline3) 
 
96
    print PDBAtomRecord.dct(aline1)
 
97
    print PDBAtomRecord.dct(aline2)
 
98
    print PDBAtomRecord.dct(aline3)
 
99
    print PDBAtomRecord.dct('')
 
100
 
 
101
 
 
102
#     1 -  6      Record name      "ATOM    "
 
103
#     7 - 11      Integer          serial     Atom serial number.
 
104
#    13 - 16      Atom             name       Atom name.
 
105
#    17           Character        altLoc     Alternate location indicator.
 
106
#    18 - 20      Residue name     resName    Residue name.
 
107
#    22           Character        chainID    Chain identifier.
 
108
#    23 - 26      Integer          resSeq     Residue sequence number.
 
109
#    27           AChar            iCode      Code for insertion of residues.
 
110
#    31 - 38      Real(8.3)        x          Orthogonal coordinates for X in 
 
111
#                                             Angstroms
 
112
#    39 - 46      Real(8.3)        y          Orthogonal coordinates for Y in 
 
113
#                                             Angstroms
 
114
#    47 - 54      Real(8.3)        z          Orthogonal coordinates for Z in 
 
115
#                                             Angstroms
 
116
#    55 - 60      Real(6.2)        occupancy  Occupancy.
 
117
#    61 - 66      Real(6.2)        tempFactor Temperature factor.
 
118
#    77 - 78      LString(2)       element    Element symbol, right-justified.
 
119
#    79 - 80      LString(2)       charge     Charge on the atom.    
 
120
 
 
121
#    Example
 
122
#             1         2         3         4         5         6         7         8
 
123
#    12345678901234567890123456789012345678901234567890123456789012345678901234567890
 
124
#    MODEL        1
 
125
#    ATOM      1  N   ALA     1      11.104   6.134  -6.504  1.00  0.00           N
 
126
#    ATOM      2  CA  ALA     1      11.639   6.071  -5.147  1.00  0.00           C
 
127
#    ...
 
128
#    ...
 
129
#    ATOM    293 1HG  GLU    18     -14.861  -4.847   0.361  1.00  0.00           H
 
130
#    ATOM    294 2HG  GLU    18     -13.518  -3.769   0.084  1.00  0.00           H
 
131
                                          
 
132
 
 
133
        
 
 
b'\\ No newline at end of file'