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

removed oldnumeric deps from MolecularSurface, PDBML, PDBMoleculeactory, ParticleProperties

parent 1ff2840a
......@@ -27,10 +27,11 @@ Molecular surfaces and volumes.
__docformat__ = 'restructuredtext'
import numpy
from MMTK import surfm
from MMTK.Collections import Collection
from MMTK import Vector
from Scientific import N
def surfaceAndVolume(object, probe_radius = 0.):
"""
......@@ -113,8 +114,8 @@ class Contact(object):
def __getitem__(self, index):
return (self.a1, self.a2)[index]
def __cmp__(a, b):
return cmp(a.dist, b.dist)
def __cmp__(self, b):
return cmp(self.dist, b.dist)
def __hash__(self):
return (self.a1, self.a2)
......@@ -160,7 +161,7 @@ def findContacts(object1, object2, contact_factor = 1.0, cutoff = 0.0):
else:
a1 = atoms[index2]
a2 = atoms[index1]
dist = N.sqrt(dist2)
dist = numpy.sqrt(dist2)
if dist >= contact_factor*(a1.vdW_radius + a2.vdW_radius + cutoff):
continue
if not done.has_key((index1, index2)):
......
......@@ -8,8 +8,7 @@ Experimental PDBML reader. It doesn't treat water molecules correctly yet
(it creates a single molecule object with all atoms of all water molecules).
"""
#import elementtree.ElementTree as ET
import cElementTree as ET
import xml.etree.ElementTree as ET
from Scientific.Geometry import Vector
from Scientific.IO.PDB import Atom, AminoAcidResidue, NucleotideResidue, \
amino_acids, nucleic_acids
......
......@@ -17,10 +17,11 @@ any force field parameters.
__docformat__ = 'restructuredtext'
import numpy
import MMTK
from MMTK.MoleculeFactory import MoleculeFactory
from Scientific.Geometry import Vector, delta
from Scientific import N
import copy
class PDBMoleculeFactory(MoleculeFactory):
......@@ -152,7 +153,7 @@ class PDBMoleculeFactory(MoleculeFactory):
rotation = transformation.tensor
translation = transformation.vector
is_asu = translation.length() < 1.e-8 and \
N.maximum.reduce(N.ravel(N.fabs((rotation
numpy.maximum.reduce(numpy.ravel(numpy.fabs((rotation
-delta).array))) < 1.e-8
if is_asu:
asu_count += 1
......
......@@ -10,10 +10,11 @@ Quantities defined for each particle in a universe
__docformat__ = 'restructuredtext'
import numpy
from MMTK import Utility
from Scientific.Geometry import Vector, isVector, Tensor, isTensor
from Scientific.indexing import index_expression
from Scientific import N
import copy
#
......@@ -89,38 +90,38 @@ class ParticleProperty(object):
def _arithmetic(self, other, op, allow_scalar=False):
a1 = self.array
return_class, a2 = self._checkCompatibility(other, allow_scalar)
if type(a2) != N.ArrayType:
a2 = N.array([a2])
if type(a2) != numpy.ndarray:
a2 = numpy.array([a2])
if len(a1.shape) != len(a2.shape):
if len(a1.shape) == 1:
a1 = a1[index_expression[...] +
(len(a2.shape)-1)*index_expression[N.NewAxis]]
(len(a2.shape)-1)*index_expression[numpy.newaxis]]
else:
a2 = a2[index_expression[...] +
(len(a1.shape)-1)*index_expression[N.NewAxis]]
(len(a1.shape)-1)*index_expression[numpy.newaxis]]
return return_class(self.universe, op(a1, a2))
def __add__(self, other):
return self._arithmetic(other, N.add)
return self._arithmetic(other, numpy.add)
__radd__ = __add__
def __sub__(self, other):
return self._arithmetic(other, N.subtract)
return self._arithmetic(other, numpy.subtract)
def __rsub__(self, other):
return self._arithmetic(other, lambda a, b: N.subtract(b, a))
return self._arithmetic(other, lambda a, b: numpy.subtract(b, a))
def __mul__(self, other):
return self._arithmetic(other, N.multiply, True)
return self._arithmetic(other, numpy.multiply, True)
__rmul__ = __mul__
def __div__(self, other):
return self._arithmetic(other, N.divide, True)
return self._arithmetic(other, numpy.divide, True)
def __rdiv__(self, other):
return self._arithmetic(other, lambda a, b: N.divide(b, a), True)
return self._arithmetic(other, lambda a, b: numpy.divide(b, a), True)
def __neg__(self):
return self.return_class(self.universe, -self.array)
......@@ -182,11 +183,11 @@ class ParticleScalar(ParticleProperty):
zeros is created and used. Otherwise, the
array myst be of shape (N,), where N is the
number of particles in the universe.
:type data_array: Scientific.N.array_type
:type data_array: Scientific.numpy.array_type
"""
ParticleProperty.__init__(self, universe, 1, 0)
if data_array is None:
self.array = N.zeros((self.n,), N.Float)
self.array = numpy.zeros((self.n,), numpy.float)
else:
self.array = data_array
if data_array.shape[0] != self.n:
......@@ -210,17 +211,17 @@ class ParticleScalar(ParticleProperty):
:returns: the highest value in the data array particle
:rtype: float
"""
return N.maximum.reduce(self.array)
return numpy.maximum.reduce(self.array)
def minimum(self):
"""
:returns: the smallest value in the data array particle
:rtype: float
"""
return N.minimum.reduce(self.array)
return numpy.minimum.reduce(self.array)
def sumOverParticles(self):
return N.add.reduce(self.array)
return numpy.add.reduce(self.array)
def applyFunction(self, function):
"""
......@@ -258,11 +259,11 @@ class ParticleVector(ParticleProperty):
zeros is created and used. Otherwise, the
array myst be of shape (N,3), where N is the
number of particles in the universe.
:type data_array: Scientific.N.array_type
:type data_array: Scientific.numpy.array_type
"""
ParticleProperty.__init__(self, universe, 1, 1)
if data_array is None:
self.array = N.zeros((self.n, 3), N.Float)
self.array = numpy.zeros((self.n, 3), numpy.float)
else:
self.array = data_array
if data_array.shape[0] != self.n:
......@@ -284,17 +285,17 @@ class ParticleVector(ParticleProperty):
raise ValueError('Variables are for different universes')
if other.value_rank == 0:
return ParticleVector(self.universe,
self.array*other.array[:,N.NewAxis])
self.array*other.array[:,numpy.newaxis])
elif other.value_rank == 1:
return ParticleScalar(self.universe,
N.add.reduce(self.array * \
numpy.add.reduce(self.array * \
other.array, -1))
else:
raise TypeError('not yet implemented')
elif isVector(other):
return ParticleScalar(self.universe,
N.add.reduce(
self.array*other.array[N.NewAxis,:],
numpy.add.reduce(
self.array*other.array[numpy.newaxis,:],
-1))
elif isTensor(other):
raise TypeError('not yet implemented')
......@@ -313,11 +314,11 @@ class ParticleVector(ParticleProperty):
:rtype: :class:`~MMTK.ParticleProperties.ParticleScalar`
"""
return ParticleScalar(self.universe,
N.sqrt(N.add.reduce(self.array**2,
numpy.sqrt(numpy.add.reduce(self.array**2,
-1)))
def sumOverParticles(self):
return Vector(N.add.reduce(self.array, 0))
return Vector(numpy.add.reduce(self.array, 0))
def norm(self):
"""
......@@ -325,7 +326,7 @@ class ParticleVector(ParticleProperty):
vector
:rtype: float
"""
return N.sqrt(N.add.reduce(N.ravel(self.array**2)))
return numpy.sqrt(numpy.add.reduce(numpy.ravel(self.array**2)))
totalNorm = norm
def scaledToNorm(self, norm):
......@@ -341,7 +342,7 @@ class ParticleVector(ParticleProperty):
"""
if self.universe != other.universe:
raise ValueError('Variables are for different universes')
return N.add.reduce(N.ravel(self.array * other.array))
return numpy.add.reduce(numpy.ravel(self.array * other.array))
def massWeightedNorm(self):
"""
......@@ -350,9 +351,9 @@ class ParticleVector(ParticleProperty):
:rtype: float
"""
m = self.universe.masses().array
return N.sqrt(N.sum(N.ravel(m[:, N.NewAxis] *
return numpy.sqrt(numpy.sum(numpy.ravel(m[:, numpy.newaxis] *
self.array**2))
/ N.sum(m))
/ numpy.sum(m))
def scaledToMassWeightedNorm(self, norm):
f = norm/self.massWeightedNorm()
......@@ -369,8 +370,8 @@ class ParticleVector(ParticleProperty):
if self.universe != other.universe:
raise ValueError('Variables are for different universes')
m = self.universe.masses().array
return N.add.reduce(N.ravel(self.array * other.array * \
m[:, N.NewAxis]))
return numpy.add.reduce(numpy.ravel(self.array * other.array * \
m[:, numpy.newaxis]))
def dyadicProduct(self, other):
"""
......@@ -382,8 +383,8 @@ class ParticleVector(ParticleProperty):
if self.universe != other.universe:
raise ValueError('Variables are for different universes')
return ParticleTensor(self.universe,
self.array[:, :, N.NewAxis] * \
other.array[:, N.NewAxis, :])
self.array[:, :, numpy.newaxis] * \
other.array[:, numpy.newaxis, :])
ParticleVector.return_class = ParticleVector
......@@ -410,7 +411,7 @@ class Configuration(ParticleVector):
zeros is created and used. Otherwise, the
array myst be of shape (N,3), where N is the
number of particles in the universe.
:type data_array: Scientific.N.array_type
:type data_array: Scientific.numpy.array_type
:param cell: the cell parameters of the universe,
i.e. the return value of universe.cellParameters()
"""
......@@ -434,7 +435,7 @@ class Configuration(ParticleVector):
__deepcopy__ = __copy__
def hasValidPositions(self):
return N.logical_and.reduce(N.ravel(N.less(self.array,
return numpy.logical_and.reduce(numpy.ravel(numpy.less(self.array,
Utility.undefined_limit)))
def convertToBoxCoordinates(self):
......@@ -469,11 +470,11 @@ class ParticleTensor(ParticleProperty):
zeros is created and used. Otherwise, the
array myst be of shape (N,3,3), where N is the
number of particles in the universe.
:type data_array: Scientific.N.array_type
:type data_array: Scientific.numpy.array_type
"""
ParticleProperty.__init__(self, universe, 1, 2)
if data_array is None:
self.array = N.zeros((self.n, 3, 3), N.Float)
self.array = numpy.zeros((self.n, 3, 3), numpy.float)
else:
self.array = data_array
if data_array.shape[0] != self.n:
......@@ -496,8 +497,8 @@ class ParticleTensor(ParticleProperty):
if other.value_rank == 0:
return ParticleTensor(self.universe,
self.array*other.array[:,
N.NewAxis,
N.NewAxis])
numpy.newaxis,
numpy.newaxis])
else:
raise TypeError('not yet implemented')
elif isVector(other):
......@@ -513,7 +514,7 @@ class ParticleTensor(ParticleProperty):
return Tensor([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])
def sumOverParticles(self):
return Tensor(N.add.reduce(self.array, 0))
return Tensor(numpy.add.reduce(self.array, 0))
def trace(self):
return ParticleScalar(self.universe,
......@@ -536,11 +537,11 @@ class SymmetricPairTensor(ParticleProperty):
zeros is created and used. Otherwise, the
array myst be of shape (N,3,N,3), where N is the
number of particles in the universe.
:type data_array: Scientific.N.array_type
:type data_array: Scientific.numpy.array_type
"""
ParticleProperty.__init__(self, universe, 2, 2)
if data_array is None:
self.array = N.zeros((self.n,3, self.n,3), N.Float)
self.array = numpy.zeros((self.n,3, self.n,3), numpy.float)
else:
self.array = data_array
if data_array.shape[0] != self.n or \
......@@ -556,7 +557,7 @@ class SymmetricPairTensor(ParticleProperty):
i2 = i2.index
if i1 > i2:
i1, i2 = i2, i1
return Tensor(N.transpose(self.array[i1,:,i2,:]))
return Tensor(numpy.transpose(self.array[i1,:,i2,:]))
else:
return Tensor(self.array[i1,:,i2,:])
......@@ -594,9 +595,9 @@ class SymmetricPairTensor(ParticleProperty):
raise ValueError('Variables are for different universes')
if other.value_rank == 1:
n = self.array.shape[0]
sa = N.reshape(self.array, (n, 3, 3*n))
oa = N.reshape(other.array, (3*n, ))
return ParticleVector(self.universe, N.dot(sa, oa))
sa = numpy.reshape(self.array, (n, 3, 3*n))
oa = numpy.reshape(other.array, (3*n, ))
return ParticleVector(self.universe, numpy.dot(sa, oa))
else:
raise TypeError('not yet implemented')
......
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