/usr/share/pyshared/MMTK/Features.py is in python-mmtk 2.7.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | # This module contains feature management classes.
#
# Written by Konrad Hinsen
#
from MMTK import Environment
import string
# Each feature class represents a feature that a certain universe
# might or might not have: fixed atoms, constraints, thermostats, etc.
# Each non-trivial algorithm that works on a universe keeps a list of
# features it can handle. This arrangement ensures a minimal
# compatibility test between universes and algorithms.
# The feature list stores all defined features.
_all = []
# The feature base class ensures that each feature is a singleton.
class Feature(object):
def __init__(self):
for f in _all:
if f.__class__ == self.__class__:
raise ValueError("feature alredy defined")
_all.append(self)
# Method to be redefined by subclasses
def isInUniverse(self, universe):
raise TypeError("must be defined in subclass")
#
# Fixed particle feature
#
class FixedParticleFeatureClass(Feature):
def isInUniverse(self, universe):
fixed = universe.getAtomBooleanArray('fixed')
return fixed.sumOverParticles() > 0
description = 'fixed particles'
FixedParticleFeature = FixedParticleFeatureClass()
#
# Distance constraints feature
#
class DistanceConstraintsFeatureClass(Feature):
def isInUniverse(self, universe):
return universe.numberOfDistanceConstraints() > 0
description = 'distance constraints'
DistanceConstraintsFeature = DistanceConstraintsFeatureClass()
#
# Nose thermostat feature
#
class NoseThermostatFeatureClass(Feature):
def isInUniverse(self, universe):
for o in universe._environment:
if o.__class__ is Environment.NoseThermostat:
return True
return False
description = 'Nose thermostat'
NoseThermostatFeature = NoseThermostatFeatureClass()
#
# Andersen barostat feature
#
class AndersenBarostatFeatureClass(Feature):
def isInUniverse(self, universe):
for o in universe._environment:
if o.__class__ is Environment.AndersenBarostat:
return True
return False
description = 'Andersen barostat'
AndersenBarostatFeature = AndersenBarostatFeatureClass()
#
# Return feature list for a universe.
#
def getFeatureList(universe):
return [f for f in _all if f.isInUniverse(universe)]
#
# Check that a feature list contains everything necessary for a universe.
#
def checkFeatures(algorithm, universe):
universe_features = set(getFeatureList(universe))
unsupported = universe_features.difference(set(algorithm.features))
if unsupported:
f = '\n'.join([f.description for f in unsupported])
raise ValueError(algorithm.__class__.__name__ +
" does not support the following features:\n" + f)
return universe_features
|