def __init__(self, *parameters): """ :param parameters: one of 1) three lattice vectors or 2) six numbers: the lengths of the three lattice vectors (a, b, c) followed by the three angles (alpha, beta, gamma). """ if len(parameters) == 6: self.a, self.b, self.c, self.alpha, self.beta, self.gamma = \ parameters e1 = Vector(self.a, 0, 0) e2 = self.b * Vector(N.cos(self.gamma), N.sin(self.gamma), 0.) e3_x = N.cos(self.beta) e3_y = (N.cos(self.alpha)-N.cos(self.beta)*N.cos(self.gamma)) \ / N.sin(self.gamma) e3_z = N.sqrt(1. - e3_x**2 - e3_y**2) e3 = self.c * Vector(e3_x, e3_y, e3_z) self.basis = (e1, e2, e3) elif len(parameters) == 3: assert isVector(parameters[0]) assert isVector(parameters[1]) assert isVector(parameters[2]) self.basis = list(parameters) e1, e2, e3 = self.basis self.a = e1.length() self.b = e2.length() self.c = e3.length() self.alpha = N.arccos(e2 * e3 / (self.b * self.c)) self.beta = N.arccos(e1 * e3 / (self.a * self.c)) self.gamma = N.arccos(e1 * e2 / (self.a * self.b)) else: raise ValueError("Parameter list incorrect") r = LA.inverse(N.transpose([e1, e2, e3])) self.reciprocal_basis = [Vector(r[0]), Vector(r[1]), Vector(r[2])]
def __call__(self, *args): arglist = [] nvector = 0 index = 0 for a in args: if isVector(a): arglist.append( Derivatives.DerivVector(a.x(), a.y(), a.z(), index, 2)) nvector = nvector + 1 index = index + 3 else: arglist.append(a) e = apply(self.func, tuple(arglist)) return EnergyGradientsForceConstants(e, nvector)
def __mul__(self, other): if isParticleProperty(other): if self.universe != other.universe: raise ValueError('Variables are for different universes') if other.value_rank == 0: return ParticleTensor( self.universe, self.array * other.array[:, N.NewAxis, N.NewAxis]) else: raise TypeError('not yet implemented') elif isVector(other): raise TypeError('not yet implemented') elif isTensor(other): raise TypeError('not yet implemented') else: return ParticleTensor(self.universe, self.array * other)
def __init__(self, point1, point2, start, ratio, point_distance, cylinder_radius=0., **attr): axis = (point2 - point1).normal() angle = Numeric.arctan(ratio) if isVector(start): rvect = start - point1 rvect = rvect - (rvect * axis) * axis radius = rvect.length() else: radius = start while 1: direction = axis.cross(randomDirection()) if direction.length() > 1.e-3: break start = point1 + radius * direction.normal() x = point_distance * Numeric.cos(angle) y = point_distance * Numeric.sin(angle) npoints = (point2 - point1).length() / y tr = Translation(y*axis+point1) \ * Rotation(axis, x/(2.*Numeric.pi*radius)) * Translation(-point1) p = start self.start_point = p objects = [] for i in range(npoints): np = tr(p) if cylinder_radius == 0.: objects.append(apply(graphics.Line, (p, np), attr)) else: objects.append( apply(graphics.Cylinder, (p, np, cylinder_radius), attr)) p = np self.end_point = p graphics.Group.__init__(self, objects)
def _checkCompatibility(self, other, allow_scalar=False): if isParticleProperty(other): if other.data_rank != self.data_rank: raise TypeError('Incompatible types') if self.universe != other.universe: raise ValueError('Variables are for different universes') if self.version != other.version: raise ValueError("Universe version numbers do not agree") if self.value_rank == other.value_rank: return self.return_class, other.array elif allow_scalar and (self.value_rank==0 or other.value_rank==0): if self.value_rank == 0: return other.return_class, other.array else: return self.return_class, other.array else: raise ValueError("Ranks do not match") elif isVector(other) or isTensor(other): if len(other.array.shape) > self.value_rank: raise TypeError('Incompatible types') return self.return_class, other.array else: return self.return_class, other