mailr17629 - in /trunk/extern/scientific_python: Geometry/ IO/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 01, 2012 - 22:12:
Author: bugman
Date: Mon Oct  1 22:12:24 2012
New Revision: 17629

URL: http://svn.gna.org/viewcvs/relax?rev=17629&view=rev
Log:
Python 3 - a number of fixes for running the ScientificPython modules in 
relax on Python 2 and 3.

This includes relative imports, converting raise statements to function 
calls, removal of the use of
many string module functions which do not exist in Python 3, etc.


Modified:
    trunk/extern/scientific_python/Geometry/TensorModule.py
    trunk/extern/scientific_python/Geometry/__init__.py
    trunk/extern/scientific_python/IO/ArrayIO.py
    trunk/extern/scientific_python/IO/FortranFormat.py
    trunk/extern/scientific_python/IO/PDB.py
    trunk/extern/scientific_python/IO/TextFile.py

Modified: trunk/extern/scientific_python/Geometry/TensorModule.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/extern/scientific_python/Geometry/TensorModule.py?rev=17629&r1=17628&r2=17629&view=diff
==============================================================================
--- trunk/extern/scientific_python/Geometry/TensorModule.py (original)
+++ trunk/extern/scientific_python/Geometry/TensorModule.py Mon Oct  1 
22:12:24 2012
@@ -208,7 +208,7 @@
             ev, vectors = eigenvectors(self.array)
             return ev, Tensor(vectors)
         else:
-            raise ValueError, 'Undefined operation'
+            raise ValueError('Undefined operation')
 
     def inverse(self):
         """

Modified: trunk/extern/scientific_python/Geometry/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/extern/scientific_python/Geometry/__init__.py?rev=17629&r1=17628&r2=17629&view=diff
==============================================================================
--- trunk/extern/scientific_python/Geometry/__init__.py (original)
+++ trunk/extern/scientific_python/Geometry/__init__.py Mon Oct  1 22:12:24 
2012
@@ -21,12 +21,12 @@
 # Pretend that Vector and Tensor are defined directly
 # in Scientific.Geometry.
 
-import VectorModule
+import extern.scientific_python.Geometry.VectorModule
 Vector = VectorModule.Vector
 isVector = VectorModule.isVector
 del VectorModule
 
-import TensorModule
+import extern.scientific_python.Geometry.TensorModule
 Tensor = TensorModule.Tensor
 isTensor = TensorModule.isTensor
 del TensorModule
@@ -52,7 +52,7 @@
 
 import sys
 if 'epydoc' in sys.modules:
-    import VectorModule, TensorModule
+    import extern.scientific_python.Geometry.VectorModule, 
extern.scientific_python.Geometry.TensorModule
     Vector = VectorModule.Vector
     isVector = VectorModule.isVector
     vm_name = VectorModule.__name__

Modified: trunk/extern/scientific_python/IO/ArrayIO.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/extern/scientific_python/IO/ArrayIO.py?rev=17629&r1=17628&r2=17629&view=diff
==============================================================================
--- trunk/extern/scientific_python/IO/ArrayIO.py (original)
+++ trunk/extern/scientific_python/IO/ArrayIO.py Mon Oct  1 22:12:24 2012
@@ -49,7 +49,7 @@
         if len(line) == 0 and len(data) > 0:
             break
         if line[0] != '#':
-            data.append(map(eval, string.split(line)))
+            data.append(map(eval, line.split()))
     a = Numeric.array(data)
     if a.shape[0] == 1 or a.shape[1] == 1:
         a = Numeric.ravel(a)
@@ -68,7 +68,7 @@
     data = []
     for line in TextFile(filename):
         if line[0] != '#':
-            data.append(map(string.atof, string.split(line)))
+            data.append(map(string.atof, line.split()))
     a = Numeric.array(data)
     if a.shape[0] == 1 or a.shape[1] == 1:
         a = Numeric.ravel(a)
@@ -87,7 +87,7 @@
     data = []
     for line in TextFile(filename):
         if line[0] != '#':
-            data.append(map(string.atoi, string.split(line)))
+            data.append(map(string.atoi, line.split()))
     a = Numeric.array(data)
     if a.shape[0] == 1 or a.shape[1] == 1:
         a = Numeric.ravel(a)

Modified: trunk/extern/scientific_python/IO/FortranFormat.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/extern/scientific_python/IO/FortranFormat.py?rev=17629&r1=17628&r2=17629&view=diff
==============================================================================
--- trunk/extern/scientific_python/IO/FortranFormat.py (original)
+++ trunk/extern/scientific_python/IO/FortranFormat.py Mon Oct  1 22:12:24 
2012
@@ -150,7 +150,7 @@
         @returns: C{True} if the line contains only whitespace
         @rtype: C{bool}
         """
-        return len(string.strip(self.text)) == 0
+        return len(self.text.strip()) == 0
 
     def _input(self):
         text = self.text
@@ -165,7 +165,7 @@
             if type == 'A':
                 value = s
             elif type == 'I':
-                s = string.strip(s)
+                s = s.strip()
                 if len(s) == 0:
                     value = 0
                 else:
@@ -178,8 +178,8 @@
                     except:
                         value = None
             elif type == 'D' or type == 'E' or type == 'F' or type == 'G':
-                s = string.lower(string.strip(s))
-                n = string.find(s, 'd')
+                s = s.strip().lower()
+                n = s.find('d')
                 if n >= 0:
                     s = s[:n] + 'e' + s[n+1:]
                 if len(s) == 0:
@@ -215,7 +215,7 @@
                         s = repr(value)
                     elif type == 'D':
                         s = ('%'+repr(length)+'.'+repr(fraction)+'e') % value
-                        n = string.find(s, 'e')
+                        n = s.find('e')
                         s = s[:n] + 'D' + s[n+1:]
                     elif type == 'E':
                         s = ('%'+repr(length)+'.'+repr(fraction)+'e') % value
@@ -225,9 +225,9 @@
                         s = ('%'+repr(length)+'.'+repr(fraction)+'g') % value
                     else:
                         raise ValueError('Not yet implemented')
-                    s = string.upper(s)
+                    s = s.upper()
                     self.text = self.text + ((length*' ')+s)[-length:]
-        self.text = string.rstrip(self.text)
+        self.text = self.text.rstrip()
 
 #
 # The class FortranFormat represents a format specification.
@@ -252,34 +252,34 @@
         @param nested: I{for internal use}
         """
         fields = []
-        format = string.strip(format)
+        format = format.strip()
         while format and format[0] != ')':
             n = 0
             while format[0] in string.digits:
                 n = 10*n + string.atoi(format[0])
                 format = format[1:]
             if n == 0: n = 1
-            type = string.upper(format[0])
+            type = format[0].upper()
             if type == "'":
-                eof = string.find(format, "'", 1)
+                eof = format.find("'", 1)
                 text = format[1:eof]
                 format = format[eof+1:]
             else:
-                format = string.strip(format[1:])
+                format = format[1:].strip()
             if type == '(':
                 subformat = FortranFormat(format, 1)
                 fields = fields + n*subformat.fields
                 format = subformat.rest
-                eof = string.find(format, ',')
+                eof = format.find(',')
                 if eof >= 0:
                     format = format[eof+1:]
             else:
-                eof = string.find(format, ',')
+                eof = format.find(',')
                 if eof >= 0:
                     field = format[:eof]
                     format = format[eof+1:]
                 else:
-                    eof = string.find(format, ')')
+                    eof = format.find(')')
                     if eof >= 0:
                         field = format[:eof]
                         format = format[eof+1:]
@@ -289,7 +289,7 @@
                 if type == "'":
                     field = (type, text)
                 else:
-                    dot = string.find(field, '.')
+                    dot = field.find('.')
                     if dot > 0:
                         length = string.atoi(field[:dot])
                         fraction = string.atoi(field[dot+1:])

Modified: trunk/extern/scientific_python/IO/PDB.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/extern/scientific_python/IO/PDB.py?rev=17629&r1=17628&r2=17629&view=diff
==============================================================================
--- trunk/extern/scientific_python/IO/PDB.py (original)
+++ trunk/extern/scientific_python/IO/PDB.py Mon Oct  1 22:12:24 2012
@@ -66,9 +66,9 @@
 
 from extern.scientific_python.IO.TextFile import TextFile
 from extern.scientific_python.IO.FortranFormat import FortranFormat, 
FortranLine
+from extern.scientific_python.IO.PDBExportFilters import export_filters
 from extern.scientific_python.Geometry import Vector, Tensor
 from extern.scientific_python import N
-from PDBExportFilters import export_filters
 import copy, string
 
 #
@@ -162,7 +162,7 @@
             self.file = TextFile(file_or_filename, mode)
         else:
             self.file = file_or_filename
-        self.output = string.lower(mode[0]) == 'w'
+        self.output = mode[0].lower() == 'w'
         self.export_filter = None
         if subformat is not None:
             export = export_filters.get(subformat, None)
@@ -200,49 +200,49 @@
             line = self.file.readline()
             if not line: return ('END', '')
             if line[-1] == '\n': line = line[:-1]
-            line = string.strip(line)
+            line = line.strip()
             if line: break
-        line = string.ljust(line, 80)
-        type = string.strip(line[:6])
+        line = line.ljust(80)
+        type = line[:6].strip()
         if type == 'ATOM' or type == 'HETATM':
             line = FortranLine(line, atom_format)
             data = {'serial_number': line[1],
                     'name': line[2],
-                    'alternate': string.strip(line[3]),
-                    'residue_name': string.strip(line[4]),
-                    'chain_id': string.strip(line[5]),
+                    'alternate': line[3].strip(),
+                    'residue_name': line[4].strip(),
+                    'chain_id': line[5].strip(),
                     'residue_number': line[6],
-                    'insertion_code': string.strip(line[7]),
+                    'insertion_code': line[7].strip(),
                     'position': Vector(line[8:11]),
                     'occupancy': line[11],
                     'temperature_factor': line[12],
-                    'segment_id': string.strip(line[13]),
-                    'element': string.strip(line[14]),
-                    'charge': string.strip(line[15])}
+                    'segment_id': line[13].strip(),
+                    'element': line[14].strip(),
+                    'charge': line[15].strip()}
             return type, data
         elif type == 'ANISOU':
             line = FortranLine(line, anisou_format)
             data = {'serial_number': line[1],
                     'name': line[2],
-                    'alternate': string.strip(line[3]),
-                    'residue_name': string.strip(line[4]),
-                    'chain_id': string.strip(line[5]),
+                    'alternate': line[3].strip(),
+                    'residue_name': line[4].strip(),
+                    'chain_id': line[5].strip(),
                     'residue_number': line[6],
-                    'insertion_code': string.strip(line[7]),
+                    'insertion_code': line[7].strip(),
                     'u': 1.e-4*Tensor([[line[8], line[11], line[12]],
                                        [line[11], line[9], line[13]],
                                        [line[12], line[13], line[10]]]),
-                    'segment_id': string.strip(line[14]),
-                    'element': string.strip(line[15]),
-                    'charge': string.strip(line[16])}
+                    'segment_id': line[14].strip(),
+                    'element': line[15].strip(),
+                    'charge': line[16].strip()}
             return type, data
         elif type == 'TER':
             line = FortranLine(line, ter_format)
             data = {'serial_number': line[1],
-                    'residue_name': string.strip(line[2]),
-                    'chain_id': string.strip(line[3]),
+                    'residue_name': line[2].strip(),
+                    'chain_id': line[3].strip(),
                     'residue_number': line[4],
-                    'insertion_code': string.strip(line[5])}
+                    'insertion_code': line[5].strip()}
             return type, data
         elif type == 'CONECT':
             line = FortranLine(line, conect_format)
@@ -314,7 +314,7 @@
             line = line + [data.get('serial_number', 1),
                            data.get('name'),
                            data.get('alternate', ''),
-                           string.rjust(data.get('residue_name', ''), 3),
+                           data.get('residue_name', '').rjust(3),
                            data.get('chain_id', ''),
                            data.get('residue_number', 1),
                            data.get('insertion_code', ''),
@@ -322,7 +322,7 @@
                            data.get('occupancy', 0.),
                            data.get('temperature_factor', 0.),
                            data.get('segment_id', ''),
-                           string.rjust(data.get('element', ''), 2),
+                           data.get('element', '').rjust(2),
                            data.get('charge', '')]
         elif type == 'ANISOU':
             format = anisou_format
@@ -332,18 +332,18 @@
             line = line + [data.get('serial_number', 1),
                            data.get('name'),
                            data.get('alternate', ''),
-                           string.rjust(data.get('residue_name'), 3),
+                           data.get('residue_name').rjust(3),
                            data.get('chain_id', ''),
                            data.get('residue_number', 1),
                            data.get('insertion_code', '')] \
                         + u \
                         + [data.get('segment_id', ''),
-                           string.rjust(data.get('element', ''), 2),
+                           data.get('element', '').rjust(2),
                            data.get('charge', '')]
         elif type == 'TER':
             format = ter_format
             line = line + [data.get('serial_number', 1),
-                           string.rjust(data.get('residue_name'), 3),
+                           data.get('residue_name').rjust(3),
                            data.get('chain_id', ''),
                            data.get('residue_number', 1),
                            data.get('insertion_code', '')]
@@ -391,7 +391,7 @@
         @type text: C{str}
         """
         while text:
-            eol = string.find(text, '\n')
+            eol = text.find('\n')
             if eol == -1:
                 eol = len(text)
             self.file.write('REMARK %s \n' % text[:eol])
@@ -419,7 +419,7 @@
             type = 'HETATM'
         else:
             type = 'ATOM'
-        name = string.upper(name)
+        name = name.upper()
         if element != '' and len(element) == 1 and name and name[0] == 
element:
             name = ' ' + name
         self.data['name'] = name
@@ -445,7 +445,7 @@
                          information in order to use different atom or
                          residue names in terminal residues.
         """
-        name  = string.upper(name)
+        name  = name.upper()
         if self.export_filter is not None:
             name, number = self.export_filter.processResidue(name, number,
                                                              terminus)
@@ -544,7 +544,7 @@
                 self.properties['element'] = name[0]
             else:
                 self.properties['element'] = name[0:2]
-        self.name = string.strip(name)
+        self.name = name.strip()
         self.parent = None
 
     def __getitem__(self, item):
@@ -808,7 +808,7 @@
 
     def __init__(self, name, atoms = None, number = None):
         self.pdbname = name
-        name = string.strip(name)
+        name = name.strip()
         if name[0] != 'D' and name[0] != 'R':
             name = 'D' + name
         Residue.__init__(self, name, atoms, number)

Modified: trunk/extern/scientific_python/IO/TextFile.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/extern/scientific_python/IO/TextFile.py?rev=17629&r1=17628&r2=17629&view=diff
==============================================================================
--- trunk/extern/scientific_python/IO/TextFile.py (original)
+++ trunk/extern/scientific_python/IO/TextFile.py Mon Oct  1 22:12:24 2012
@@ -14,7 +14,7 @@
 gzip = None
 try:
     _version = map(string.atoi,
-                   string.split(string.split(sys.version)[0], '.'))
+                   sys.version.split()[0], '.').split()
     if _version >= [1, 5, 2]:
         try:
             import gzip
@@ -48,7 +48,7 @@
         @param mode: file access mode: 'r' (read), 'w' (write), or 'a' 
(append)
         @type mode: C{str}
         """
-        if string.find(filename, ':/') > 1: # URL
+        if filename.find(':/') > 1: # URL
             if mode != 'r':
                 raise IOError("can't write to a URL")
             import urllib




Related Messages


Powered by MHonArc, Updated Mon Oct 01 22:20:01 2012