How to use the openpathsampling.ensemble.Ensemble function in openpathsampling

To help you get started, we’ve selected a few openpathsampling examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
# return EmptyEnsemble()
            # else:
            # return RelativeComplementEnsemble(self, other)

            # This is not correct for all ensembles.
            # def __invert__(self):
            # return NegatedEnsemble(self)

    @staticmethod
    def _indent(s):
        spl = s.split('\n')
        spl = ['  ' + p for p in spl]
        return '\n'.join(spl)


class EmptyEnsemble(Ensemble):
    """
    The empty path ensemble of no trajectories.
    """

    def __init__(self):
        super(EmptyEnsemble, self).__init__()

    def __call__(self, trajectory, trusted=None, candidate=False):
        return False

    def can_append(self, trajectory, trusted=False):
        return False

    def can_prepend(self, trajectory, trusted=False):
        return False
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
def __call__(self, trajectory, trusted=None, candidate=False):
        return not self.ensemble(trajectory, trusted, candidate)

    def can_append(self, trajectory, trusted=False):
        # We cannot guess the result here so keep on running forever
        return True

    def can_prepend(self, trajectory, trusted=False):
        # We cannot guess the result here so keep on running forever
        return True

    def _str(self):
        return 'not ' + str(self.ensemble)


class EnsembleCombination(Ensemble):
    """
    Logical combination of two ensembles
    """

    def __init__(self, ensemble1, ensemble2, fnc, str_fnc):
        super(EnsembleCombination, self).__init__()
        self.ensemble1 = ensemble1
        self.ensemble2 = ensemble2
        self.fnc = fnc
        self.sfnc = str_fnc

    def to_dict(self):
        return {'ensemble1': self.ensemble1, 'ensemble2': self.ensemble2}

    def _generalized_short_circuit(self, combo, f1, f2, trajectory, trusted,
                                   fname=""):
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
def __init__(self):
        '''
        A path volume defines a set of paths.
        '''
        super(Ensemble, self).__init__()
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
return EmptyEnsemble()
        else:
            return NegatedEnsemble(other)

    def __or__(self, other):
        return self

    def __str__(self):
        return 'all'

    def oom_matrix(self, oom):
        # Full matrix
        return None


class NegatedEnsemble(Ensemble):
    '''
    Negates an Ensemble and simulates a `not` statement
    '''
    def __init__(self, ensemble):
        super(NegatedEnsemble, self).__init__()
        self.ensemble = ensemble
        
    def __call__(self, trajectory, trusted=None):
        return not self.ensemble(trajectory, trusted)

    def can_append(self, trajectory, trusted=False):
        # We cannot guess the result here so keep on running forever
        return True

    def can_prepend(self, trajectory, trusted=False):
        # We cannot guess the result here so keep on running forever
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
def __str__(self):
        if type(self.length) is int:
            return 'len(x) = {0}'.format(self.length)
        else:
            start = self.length.start
            if start is None:
                start = 0
            stop = self.length.stop
            if stop is None:
                stop = 'infty'
            else:
                stop = str(self.length.stop - 1)
            return 'len(x) in [{0}, {1}]'.format(start, stop)


class VolumeEnsemble(Ensemble):
    '''
    Path ensembles based on the Volume object
    '''    
    def __init__(self, volume, trusted = True):
        super(VolumeEnsemble, self).__init__()
        self.volume = volume
        self.trusted = trusted

    @property
    def _volume(self):
        '''
        The volume that is used in the specification.
        '''
        return self.volume
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
str(ens_final)
                        )
                        ens_final -= 1
                        ens_num = ens_final
                        subtraj_final = len(trajectory)
                        self.update_cache(cache, ens_num, ens_final, subtraj_final)

    def __str__(self):
        head = "[\n"
        tail = "\n]"
        sequence_str = ",\n".join([str(ens) for ens in self.ensembles])
        return head+sequence_str+tail



class LengthEnsemble(Ensemble):
    '''
    The ensemble of trajectories of a given length
    '''
    def __init__(self, length):
        '''
        A path ensemble that describes path of a specific length
        
        Parameters
        ----------
        length : int or slice
            The specific length (int) or the range of allowed trajectory lengths (slice)
        '''

        super(LengthEnsemble, self).__init__()
        self.length = length
        pass
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
return False

    def can_prepend(self, trajectory, trusted=False):
        return self._generic_can_prepend(trajectory, trusted, strict=False)

    def strict_can_prepend(self, trajectory, trusted=False):
        return self._generic_can_prepend(trajectory, trusted, strict=True)

    def _str(self):
        head = "[\n"
        tail = "\n]"
        sequence_str = ",\n".join([str(ens) for ens in self.ensembles])
        return head + sequence_str + tail


class LengthEnsemble(Ensemble):
    """
    The ensemble of trajectories of a given length
    """

    def __init__(self, length):
        """
        A path ensemble that describes path of a specific length

        Parameters
        ----------
        length : int or slice
            The specific length (int) or the range of allowed trajectory
            lengths (slice)
        """
        #TODO: remove support for slice?
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
class IntersectionEnsemble(EnsembleCombination):
    def __init__(self, ensemble1, ensemble2):
        super(IntersectionEnsemble, self).__init__(ensemble1, ensemble2, fnc = lambda a,b : a and b, str_fnc = '{0}\nand\n{1}')


class SymmetricDifferenceEnsemble(EnsembleCombination):
    def __init__(self, ensemble1, ensemble2):
        super(SymmetricDifferenceEnsemble, self).__init__(ensemble1, ensemble2, fnc = lambda a,b : a ^ b, str_fnc = '{0}\nxor\n{1}')


class RelativeComplementEnsemble(EnsembleCombination):
    def __init__(self, ensemble1, ensemble2):
        super(RelativeComplementEnsemble, self).__init__(ensemble1, ensemble2, fnc = lambda a,b : a and not b, str_fnc = '{0}\nand not\n{1}')


class SequentialEnsemble(Ensemble):
    """Ensemble which satisfies several subensembles in sequence.

    Attributes
    ----------
    ensembles : tuple of Ensemble
        The ensembles, in time-order of when they should occur in the
        trajectory.
    min_overlap : int or tuple of int
        The minimum number of frames that overlap between two ensembles in
        the sequence. A positive number n indicates that at least n frames
        must be in both ensembles at the transition between them. A negative
        number -n indicates that at least n frames in neither ensemble at
        the transition between them. If given as a list, the list should be
        of length len(ensembles)-1, with one value for each transition. If
        given as an integer, that value will be used for all transitions.
    max_overlap : int or list of int
github openpathsampling / openpathsampling / openpathsampling / attic / ensemble_store.py View on Github external
def __init__(self, storage):
        super(EnsembleStorage, self).__init__(storage, Ensemble, named=True)
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
def can_prepend(self, trajectory, trusted=False):
        if Ensemble.use_shortcircuit:
            a = self.ensemble1.can_prepend(trajectory, trusted)
            res_true = self._continue_fnc(a, True)
            res_false = self._continue_fnc(a, False)
            if res_false == res_true:
                # result is independent of ensemble_b so ignore it
                return res_true
            else:
                b = self.ensemble2.can_prepend(trajectory, trusted)
                if b == True:
                    return res_true
                else:
                    return res_false
        else:
            return self.fnc(self.ensemble1.can_prepend(trajectory, trusted), 
                            self.ensemble2.can_prepend(trajectory, trusted))