2323#
2424#--
2525
26+ from __future__ import print_function , absolute_import
27+
2628'''Readers ab initio vibrational calculations.
2729'''
2830
@@ -84,20 +86,20 @@ def __init__(self, filename, field_labels=[]):
8486 # Read atomic masses for atomtype
8587 masses = np .asarray ([float (atom .findall ('c' )[2 ].text ) for atom in self .root .findall (".//*[@name='atomtypes']/set" )[0 ]])* amu
8688 self .fields ['masses' ] = np .zeros (self .fields ['numbers' ].shape )
87- for iatype in xrange (masses .shape [0 ]):
89+ for iatype in range (masses .shape [0 ]):
8890 self .fields ['masses' ][atomtypes == iatype ] = masses [iatype ]
8991 # Read SCF energies
9092 self .fields ['energies' ] = np .array ([float (step .find ('energy/i[@name="e_fr_energy"]' ).text )* electronvolt \
9193 for step in self .root .findall ('.//calculation' )])
9294 # Read all requested arrays
9395 for label in field_labels :
94- if not label in tag_dictionary .keys ():
95- raise NotImplementedError , "Failed to read %s from xml file" % label
96+ if not label in list ( tag_dictionary .keys () ):
97+ raise NotImplementedError ( "Failed to read %s from xml file" % label )
9698 self .fields [label ] = self .read_array (tag_dictionary [label ][0 ], unit = tag_dictionary [label ][1 ])
9799 # Convert fractional to Cartesian coordinates
98100 self .fields ['pos_init' ] = np .dot (self .fields ['pos_init' ], self .fields ['rvecs_init' ])
99101 # Hessian is mass-weighted, we want the pure second derivatives
100- if 'hessian' in self .fields .keys ():
102+ if 'hessian' in list ( self .fields .keys () ):
101103 m3 = np .sqrt (np .array (sum ([[m ,m ,m ] for m in self .fields ['masses' ]],[])))
102104 self .fields ['hessian' ] = m3 .reshape ((- 1 ,1 ))* self .fields ['hessian' ]* m3
103105
@@ -154,39 +156,39 @@ def read_abinitio(fn, do_hess=True):
154156def make_yaff_ei (fn , charges , bcis = None , radii = None ):
155157 assert charges is not None or bcis is not None , 'Either charges or bcis should be parsed'
156158 f = open (fn , 'w' )
157- print >> f , '#Fixed charges'
158- print >> f , '#---------------'
159- print >> f , ''
160- print >> f , 'FIXQ:UNIT Q0 e'
161- print >> f , 'FIXQ:UNIT P e'
162- print >> f , 'FIXQ:UNIT R angstrom'
163- print >> f , 'FIXQ:SCALE 1 1.0'
164- print >> f , 'FIXQ:SCALE 2 1.0'
165- print >> f , 'FIXQ:SCALE 3 1.0'
166- print >> f , 'FIXQ:DIELECTRIC 1.0'
167- print >> f , ''
159+ print ( '#Fixed charges' , file = f )
160+ print ( '#---------------' , file = f )
161+ print ( '' , file = f )
162+ print ( 'FIXQ:UNIT Q0 e' , file = f )
163+ print ( 'FIXQ:UNIT P e' , file = f )
164+ print ( 'FIXQ:UNIT R angstrom' , file = f )
165+ print ( 'FIXQ:SCALE 1 1.0' , file = f )
166+ print ( 'FIXQ:SCALE 2 1.0' , file = f )
167+ print ( 'FIXQ:SCALE 3 1.0' , file = f )
168+ print ( 'FIXQ:DIELECTRIC 1.0' , file = f )
169+ print ( '' , file = f )
168170 if charges is not None or radii is not None :
169- print >> f , '# Atomic parameters'
170- print >> f , '# ----------------------------------------------------'
171- print >> f , '# KEY label Q_0A R_A'
172- print >> f , '# ----------------------------------------------------'
171+ print ( '# Atomic parameters' , file = f )
172+ print ( '# ----------------------------------------------------' , file = f )
173+ print ( '# KEY label Q_0A R_A' , file = f )
174+ print ( '# ----------------------------------------------------' , file = f )
173175 if charges is not None :
174- ffatypes = charges .keys ()
176+ ffatypes = list ( charges .keys () )
175177 else :
176- ffatypes = radii .keys ()
178+ ffatypes = list ( radii .keys () )
177179 for ffatype in ffatypes :
178180 charge , radius = 0.0 , 0.0
179181 if charges is not None : charge = charges [ffatype ]
180182 if radii is not None : radius = radii [ffatype ]
181- print >> f , 'FIXQ:ATOM %8s % 13.10f %12.10f' % (ffatype , charge , radius / angstrom )
183+ print ( 'FIXQ:ATOM %8s % 13.10f %12.10f' % (ffatype , charge , radius / angstrom ), file = f )
182184 if bcis is not None :
183- print >> f , '# Bond parameters'
184- print >> f , '# ----------------------------------------------------'
185- print >> f , '# KEY label0 label1 P_AB '
186- print >> f , '# ----------------------------------------------------'
187- for key , bci in bcis .iteritems ():
185+ print ( '# Bond parameters' , file = f )
186+ print ( '# ----------------------------------------------------' , file = f )
187+ print ( '# KEY label0 label1 P_AB ' , file = f )
188+ print ( '# ----------------------------------------------------' , file = f )
189+ for key , bci in bcis .items ():
188190 ffatype1 , ffatype2 = key .split ('.' )
189- print >> f , 'FIXQ:BOND %8s %8s % 12.10f' % (ffatype1 , ffatype2 , bci )
191+ print ( 'FIXQ:BOND %8s %8s % 12.10f' % (ffatype1 , ffatype2 , bci ), file = f )
190192 f .close ()
191193
192194
@@ -211,7 +213,7 @@ def read_bci_constraints(fn):
211213 master , suffix , sign = line .split (':' )
212214 slaves = [(slave .strip (), float (sign )) for slave in suffix .split (',' )]
213215 label = master .strip ()
214- if label in constraints .keys ():
216+ if label in list ( constraints .keys () ):
215217 for slave in slaves : constraints [label ].append (slave )
216218 else :
217219 constraints [label ] = slaves
@@ -413,7 +415,7 @@ def dump_charmm22_prm(valence, fn):
413415
414416def _atoms_to_charmm22_psf (system ):
415417 result = ['{:8d} !NATOM' .format (system .natom )]
416- for iatom in xrange (system .natom ):
418+ for iatom in range (system .natom ):
417419 ffatype = system .get_ffatype (iatom )
418420 if len (ffatype ) > 4 :
419421 log .warning ('Atom type too long for CHARMM PSF file: {}' .format (ffatype ))
@@ -977,13 +979,13 @@ def dump_yaff(valence, fn):
977979 f = open (fn , 'w' )
978980 for section in sections :
979981 if len (section ['PARS' ].lines )== 0 : continue
980- print >> f , '# %s' % section .prefix
981- print >> f , '#-%s' % ('-' * len (section .prefix ))
982+ print ( '# %s' % section .prefix , file = f )
983+ print ( '#-%s' % ('-' * len (section .prefix )), file = f )
982984 for line in section ['UNIT' ].lines :
983- print >> f , '%s:UNIT %s' % (section .prefix , line )
984- print >> f , ''
985+ print ( '%s:UNIT %s' % (section .prefix , line ), file = f )
986+ print ( '' , file = f )
985987 for line in section ['PARS' ].lines :
986- print >> f , '%s:PARS %s' % (section .prefix , line )
987- print >> f , ''
988- print >> f , ''
988+ print ( '%s:PARS %s' % (section .prefix , line ), file = f )
989+ print ( '' , file = f )
990+ print ( '' , file = f )
989991 f .close ()
0 commit comments