Commit a09f317d authored by eric pellegrini's avatar eric pellegrini
Browse files

removed oldnumeric deps from ProteinFriction, Subspace, Utility, Visualization, XML

parent 93907630
......@@ -9,8 +9,9 @@ A friction constant model for |C_alpha| models of proteins
__docformat__ = 'restructuredtext'
import numpy
import MMTK.ParticleProperties
from Scientific import N
def calphaFrictionConstants(protein, set=2):
"""
......@@ -27,7 +28,7 @@ def calphaFrictionConstants(protein, set=2):
for residue in chain:
a = residue.peptide.C_alpha
m = atoms.selectShell(a.position(), radius).mass()
d = 3.*m/(4.*N.pi*radius**3)
d = 3.*m/(4.*numpy.pi*radius**3)
if set == 1: # linear fit to initial slope
f[a] = max(1000., 121.2*d-8600)
elif set == 2: # exponential fit 400 steps
......
......@@ -17,26 +17,22 @@ calculations or for analyzing complex motions. For an explanation, see:
__docformat__ = 'restructuredtext'
import numpy
from MMTK import Utility, ParticleProperties
from Scientific.Geometry import Vector, ex, ey, ez
from Scientific import N
import copy
#
# Import LAPACK routines
#
try:
array_package = N.package
except AttributeError:
array_package = "Numeric"
dgesdd = None
try:
if array_package == "Numeric":
from lapack_lite import dgesdd, LapackError
else:
from numpy.linalg.lapack_lite import dgesdd, LapackError
except ImportError: pass
from numpy.linalg.lapack_lite import dgesdd, LapackError
except ImportError:
pass
if dgesdd is None:
try:
# PyLAPACK
......@@ -44,19 +40,18 @@ if dgesdd is None:
except ImportError: pass
if dgesdd:
n = 1
array = N.zeros((n, n), N.Float)
sv = N.zeros((n,), N.Float)
u = N.zeros((n, n), N.Float)
vt = N.zeros((n, n), N.Float)
work = N.zeros((1,), N.Float)
int_types = [N.Int, N.Int8, N.Int16, N.Int32]
array = numpy.zeros((n, n), numpy.float)
sv = numpy.zeros((n,), numpy.float)
u = numpy.zeros((n, n), numpy.float)
vt = numpy.zeros((n, n), numpy.float)
work = numpy.zeros((1,), numpy.float)
int_types = [numpy.int, numpy.int8, numpy.int16, numpy.int32]
try:
int_types.append(N.Int64)
int_types.append(N.Int128)
int_types.append(numpy.int64)
except AttributeError:
pass
for int_type in int_types:
iwork = N.zeros((1,), int_type)
iwork = numpy.zeros((1,), int_type)
try:
dgesdd('S', n, n, array, n, sv, u, n, vt, n, work, -1, iwork, 0)
break
......@@ -73,13 +68,13 @@ class ParticleVectorSet(object):
def __init__(self, universe, data):
self.universe = universe
if type(data) == N.arraytype:
if type(data) == numpy.ndarray:
self.n = data.shape[0]
self.array = data
else:
self.n = data
self.array = N.zeros((self.n, universe.numberOfAtoms(), 3),
N.Float)
self.array = numpy.zeros((self.n, universe.numberOfAtoms(), 3),
numpy.float)
def __len__(self):
return self.n
......@@ -128,38 +123,38 @@ class Subspace(object):
:returns: the basis
"""
if self._basis is None:
basis = N.array([v.array for v in self.vectors], N.Float)
basis = numpy.array([v.array for v in self.vectors], numpy.float)
shape = basis.shape
nvectors = shape[0]
natoms = shape[1]
basis.shape = (nvectors, 3*natoms)
sv = N.zeros((min(nvectors, 3*natoms),), N.Float)
sv = numpy.zeros((min(nvectors, 3*natoms),), numpy.float)
min_n_m = min(3*natoms, nvectors)
vt = N.zeros((nvectors, min_n_m), N.Float)
work = N.zeros((1,), N.Float)
iwork = N.zeros((8*min_n_m,), int_type)
vt = numpy.zeros((nvectors, min_n_m), numpy.float)
work = numpy.zeros((1,), numpy.float)
iwork = numpy.zeros((8*min_n_m,), int_type)
if 3*natoms >= nvectors:
result = dgesdd('O', 3*natoms, nvectors, basis, 3*natoms,
sv, basis, 3*natoms, vt, min_n_m,
work, -1, iwork, 0)
work = N.zeros((int(work[0]),), N.Float)
work = numpy.zeros((int(work[0]),), numpy.float)
result = dgesdd('O', 3*natoms, nvectors, basis, 3*natoms,
sv, basis, 3*natoms, vt, min_n_m,
work, work.shape[0], iwork, 0)
u = basis
else:
u = N.zeros((min_n_m, 3*natoms), N.Float)
u = numpy.zeros((min_n_m, 3*natoms), numpy.float)
result = dgesdd('S', 3*natoms, nvectors, basis, 3*natoms,
sv, u, 3*natoms, vt, min_n_m,
work, -1, iwork, 0)
work = N.zeros((int(work[0]),), N.Float)
work = numpy.zeros((int(work[0]),), numpy.float)
result = dgesdd('S', 3*natoms, nvectors, basis, 3*natoms,
sv, u, 3*natoms, vt, min_n_m,
work, work.shape[0], iwork, 0)
if result['info'] != 0:
raise ValueError('Lapack SVD: ' + `result['info']`)
svmax = N.maximum.reduce(sv)
nvectors = N.add.reduce(N.greater(sv, 1.e-10*svmax))
svmax = numpy.maximum.reduce(sv)
nvectors = numpy.add.reduce(numpy.greater(sv, 1.e-10*svmax))
u = u[:nvectors]
u.shape = (nvectors, natoms, 3)
self._basis = ParticleVectorSet(self.universe, u)
......@@ -173,9 +168,9 @@ class Subspace(object):
"""
vector = vector.array
basis = self.getBasis().array
p = N.zeros(vector.shape, N.Float)
p = numpy.zeros(vector.shape, numpy.float)
for bv in basis:
N.add(N.add.reduce(N.ravel(bv*vector))*bv, p, p)
numpy.add(numpy.add.reduce(numpy.ravel(bv*vector))*bv, p, p)
return ParticleProperties.ParticleVector(self.universe, p)
def projectionComplementOf(self, vector):
......@@ -317,7 +312,7 @@ class RigidMotionSubspace(Subspace):
v = ParticleProperties.ParticleVector(universe)
for a in rb_atoms:
v[a] = d
vectors.append(v/N.sqrt(len(rb_atoms)))
vectors.append(v/numpy.sqrt(len(rb_atoms)))
if len(rb_atoms) > 1:
center = o.centerOfMass()
iv = len(vectors)-3
......@@ -327,7 +322,7 @@ class RigidMotionSubspace(Subspace):
v[a] = d.cross(a.position()-center)
for vt in vectors[iv:]:
v -= v.dotProduct(vt)*vt
norm_sq = N.sqrt(v.dotProduct(v))
norm_sq = numpy.sqrt(v.dotProduct(v))
if norm_sq > 0.:
vectors.append(v/norm_sq)
......
......@@ -5,7 +5,8 @@
#
import os, sys
from Scientific import N
import numpy
# Constants
......@@ -154,7 +155,7 @@ def isSequenceObject(obj):
def isDefinedPosition(p):
if p is None:
return False
if N.add.reduce(N.greater(p.array, undefined_limit)) > 0:
if numpy.add.reduce(numpy.greater(p.array, undefined_limit)) > 0:
return False
return True
......@@ -180,17 +181,10 @@ def warning(text):
# Pickler and unpickler taking care of non-pickled objects
#
try:
array_package = N.package
except AttributeError:
array_package = 'Numeric'
if array_package == 'Numeric':
BasePickler = N.Pickler
BaseUnpickler = N.Unpickler
else:
from pickle import Pickler as BasePickler
from pickle import Unpickler as BaseUnpickler
del array_package
from pickle import Pickler as BasePickler
from pickle import Unpickler as BaseUnpickler
from pickle import UnpicklingError
class Pickler(BasePickler):
......
......@@ -34,8 +34,9 @@ directory specification.
__docformat__ = 'restructuredtext'
import numpy
from MMTK import Units, Utility
from Scientific import N
import subprocess, sys, tempfile, os
#
......@@ -174,8 +175,8 @@ class Viewable(object):
if color is None:
color_values = options.get('color_values', None)
if color_values is not None:
lower = N.minimum.reduce(color_values.array)
upper = N.maximum.reduce(color_values.array)
lower = numpy.minimum.reduce(color_values.array)
upper = numpy.maximum.reduce(color_values.array)
options['color_scale'] = module.ColorScale((lower, upper))
try:
distance_fn = self.universe().distanceVector
......
......@@ -12,11 +12,11 @@ be considered experimental and subject to change.
__docformat__ = 'restructuredtext'
import numpy
import MMTK
from MMTK.MoleculeFactory import MoleculeFactory
from xml.etree.ElementTree import iterparse
from Scientific import N
class XMLMoleculeFactory(MoleculeFactory):
......@@ -104,5 +104,5 @@ class XMLMoleculeFactory(MoleculeFactory):
array[:, 0] = x
array[:, 1] = y
array[:, 2] = z
N.multiply(array, factor, array)
numpy.multiply(array, factor, array)
self.universe = universe
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment