Remove unused MultiVector
This commit is contained in:
committed by
Thomas Holder
parent
83c17217f9
commit
9d4b59c825
@@ -357,21 +357,3 @@ def make_tidy_atom_label(name, element):
|
|||||||
else: # The element should occupy the two first chars
|
else: # The element should occupy the two first chars
|
||||||
label = '{0:<4s}'.format(name)
|
label = '{0:<4s}'.format(name)
|
||||||
return label
|
return label
|
||||||
|
|
||||||
|
|
||||||
def get_sorted_configurations(configuration_keys):
|
|
||||||
"""Extract and sort configurations.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
configuration_keys: list of configuration keys
|
|
||||||
Returns:
|
|
||||||
list of configurations
|
|
||||||
"""
|
|
||||||
configurations = list(configuration_keys)
|
|
||||||
configurations.sort(key=configuration_compare)
|
|
||||||
return configurations
|
|
||||||
|
|
||||||
|
|
||||||
def configuration_compare(conf):
|
|
||||||
"""TODO - figure out what this function does."""
|
|
||||||
return 100*int(conf[1:-2]) + ord(conf[-1])
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ Vector algebra for PROPKA.
|
|||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
from typing import Optional, Protocol, Union
|
from typing import Optional, Protocol, Union
|
||||||
from propka.lib import get_sorted_configurations
|
|
||||||
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -296,146 +295,3 @@ def rotate_atoms_around_y_axis(theta: float) -> Matrix4x4:
|
|||||||
a43i=0.0,
|
a43i=0.0,
|
||||||
a44i=1.0
|
a44i=1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MultiVector:
|
|
||||||
"""Collection of vectors for multiple configurations of atoms.
|
|
||||||
|
|
||||||
TODO - this class does not appear to be used or covered by tests
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, atom1=None, atom2=None):
|
|
||||||
"""Initialize with atom configurations.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
atom1: first atom to define vector
|
|
||||||
atom2: second atom to define vector
|
|
||||||
"""
|
|
||||||
self.vectors = []
|
|
||||||
self.keys = []
|
|
||||||
self.result = None
|
|
||||||
# store vectors for all configurations of atoms
|
|
||||||
if atom1 is not None:
|
|
||||||
self.keys = get_sorted_configurations(atom1.configurations.keys())
|
|
||||||
if atom2 is not None:
|
|
||||||
keys2 = get_sorted_configurations(atom2.configurations.keys())
|
|
||||||
if self.keys != keys2:
|
|
||||||
str_ = ('Cannot make multi vector: Atomic configurations '
|
|
||||||
'mismatch for\n {0:s}\n {1:s}\n'.format(
|
|
||||||
atom1, atom2))
|
|
||||||
raise KeyError(str_)
|
|
||||||
for key in self.keys:
|
|
||||||
atom1.setConfiguration(key)
|
|
||||||
if atom2 != 0:
|
|
||||||
atom2.setConfiguration(key)
|
|
||||||
vec = Vector(atom1=atom1, atom2=atom2)
|
|
||||||
self.vectors.append(vec)
|
|
||||||
|
|
||||||
def __getattribute__(self, name):
|
|
||||||
try:
|
|
||||||
return object.__getattribute__(self, name)
|
|
||||||
except AttributeError:
|
|
||||||
return self.do_job(name)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
res = ''
|
|
||||||
for i, key in enumerate(self.keys):
|
|
||||||
res += '{0:s} {1:s}\n'.format(key, self.vectors[i])
|
|
||||||
return res
|
|
||||||
|
|
||||||
def do_job(self, job):
|
|
||||||
"""Append vectors to configuration.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
job: name of function to apply to vectors
|
|
||||||
Returns:
|
|
||||||
TODO - figure out what this is
|
|
||||||
"""
|
|
||||||
self.result = MultiVector()
|
|
||||||
for i, vector in enumerate(self.vectors):
|
|
||||||
func = getattr(vector, job)
|
|
||||||
self.result.vectors.append(func())
|
|
||||||
self.result.keys.append(self.keys[i])
|
|
||||||
return self.get_result
|
|
||||||
|
|
||||||
@property
|
|
||||||
def get_result(self):
|
|
||||||
"""Return the latest result."""
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
def generic_operation(self, operation, other):
|
|
||||||
"""Perform a generic operation between two MultiVector objects.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation: operation to perform (string)
|
|
||||||
other: other MultiVector object
|
|
||||||
"""
|
|
||||||
if self.keys != other.keys:
|
|
||||||
raise 'Incompatible keys'
|
|
||||||
self.result = MultiVector()
|
|
||||||
for i in range(len(self.vectors)):
|
|
||||||
self.result.vectors.append(
|
|
||||||
# TODO - eliminate eval() or entire class
|
|
||||||
eval(
|
|
||||||
'self.vectors[{0:d}] {1:s} other.vectors[{2:d}]'.format(
|
|
||||||
i, operation, i)))
|
|
||||||
self.result.keys.append(self.keys[i])
|
|
||||||
|
|
||||||
def __add__(self, other):
|
|
||||||
self.generic_operation('+', other)
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
def __sub__(self, other):
|
|
||||||
self.generic_operation('-', other)
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
def __mul__(self, other):
|
|
||||||
self.generic_operation('*', other)
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
def __pow__(self, other):
|
|
||||||
self.generic_operation('**', other)
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def generic_self_operation(_):
|
|
||||||
"""TODO - delete this."""
|
|
||||||
return
|
|
||||||
|
|
||||||
def __neg__(self):
|
|
||||||
self.generic_operation('*', -1.0)
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
def rescale(self, new_length):
|
|
||||||
"""Rescale multi-vector to new length.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
new_length: new length for multi-vector
|
|
||||||
Result:
|
|
||||||
MultiVector object
|
|
||||||
"""
|
|
||||||
self.result = MultiVector()
|
|
||||||
for i, vector in enumerate(self.vectors):
|
|
||||||
self.result.vectors.append(vector.rescale(new_length))
|
|
||||||
self.result.keys.append(self.keys[i])
|
|
||||||
return self.res
|
|
||||||
|
|
||||||
|
|
||||||
def rotate_multi_vector_around_an_axis(theta, axis, vec):
|
|
||||||
"""Rotate a multi-vector around an axis.
|
|
||||||
|
|
||||||
NOTE - both axis ans v must be MultiVectors.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
theta: angle (in radians)
|
|
||||||
axis: multi-vector axis
|
|
||||||
vec: multi-vector vector
|
|
||||||
"""
|
|
||||||
if axis.keys != vec.keys:
|
|
||||||
raise 'Incompatible keys in rotate MultiVector'
|
|
||||||
res = MultiVector()
|
|
||||||
for i, key in enumerate(vec.keys):
|
|
||||||
res.vectors.append(rotate_vector_around_an_axis(
|
|
||||||
theta, axis.vectors[i], vec.vectors[i]))
|
|
||||||
res.keys.append(key)
|
|
||||||
return res
|
|
||||||
|
|||||||
Reference in New Issue
Block a user