Esempio n. 1
0
    def initialize(self):
        """
        Initializes system
        """
        # Many of these are now specified in the west.cfg file.
        # They are left here for legacy purposes.
        self.pcoord_ndim = 2
        self.pcoord_len = 11
        self.pcoord_dtype = numpy.float32
        # As the RMSD coordinate is taken relative to the coil, aligned on the coil,
        # it will remain sensitive to coil changes.  It's not awful to assume the maximum is
        # not dissimilar to the maximum for the distance; something around 57 A, as
        # that would take into account the peptide flipping completely around.
        # However, we must bin much finer.
        self.rmsd_binbounds         = [0.0+0.1*i for i in xrange(0,39)] + \
                                      [4.0+0.2*i for i in xrange(0,54)] + \
                                      [15.0+11.0*i for i in xrange(0,5)] + [float('inf')]

        # It's best not to place these at the integer boundaries, due to
        # oddities with the way numpy/h5py stores the values inside the west.h5 file.
        # Given that we are starting in the coil conformation, the 'unknown state'
        # (that is, 1.5 to float, or 2) will never be used; our bins will never be more
        # than 66% filled.

        self.color_binbounds = [-0.5, 0.5, 1.5, float('inf')]

        # A simple rectilinear binmapper, with the third dimension as color, to ensure good sampling.
        self.bin_mapper = RectilinearBinMapper(
            [self.rmsd_binbounds, self.color_binbounds])
        self.bin_target_counts = numpy.empty((self.bin_mapper.nbins, ),
                                             numpy.int)
        self.bin_target_counts[...] = 8
Esempio n. 2
0
 def initialize(self):
     self.pcoord_ndim = 1
     self.pcoord_len = pcoord_len
     self.pcoord_dtype = pcoord_dtype
     binbounds = ([0.0] + [2.8, 2.88, 3.0, 3.10, 3.29, 3.79, 3.94, 4.12, 4.39, 5.43] + [5.90+1.0*i for i in xrange(0,11)] + [30,float('inf')]) 
     self.bin_mapper = RectilinearBinMapper([binbounds])
     self.bin_target_counts = np.empty((self.bin_mapper.nbins,), np.int)
     self.bin_target_counts[...] = 24
Esempio n. 3
0
 def initialize(self):
     self.pcoord_ndim = 1
     self.pcoord_dtype = numpy.float32
     self.pcoord_len = 5
     self.bin_mapper = RectilinearBinMapper([ list(numpy.arange(0.0, 10.1, 0.1)) ] )
     self.bin_target_counts = numpy.empty((self.bin_mapper.nbins,), numpy.int_)
     self.bin_target_counts[...] = 10
     self.test_variable_2 = "And I'm the second one"
Esempio n. 4
0
 def setup(self):
     system = WESTSystem()
     system.bin_mapper = RectilinearBinMapper([[0.0, 1.0, 2.0]])
     system.bin_target_counts = numpy.array([4, 4])
     system.pcoord_len = 2
     self.we_driver = WEDriver(system=system)
     self.system = system
     self._seg_id = 0
Esempio n. 5
0
 def initialize(self):
     self.pcoord_ndim = 2
     self.pcoord_len = 21
     self.pcoord_dtype = numpy.float32
     binbounds1 = [0.5*i for i in range(0,21)] + [i for i in range(11,61)] + [float('inf')]
     binbounds2 = [0.0, 3.0, float('inf')]
     self.bin_mapper = RectilinearBinMapper([binbounds1, binbounds2])
     self.bin_target_counts = numpy.empty((self.bin_mapper.nbins,), numpy.int)
     self.bin_target_counts[...] = 8
Esempio n. 6
0
    def initialize(self):
        self.pcoord_ndim = 1
        self.pcoord_len = 21
        self.pcoord_dtype = numpy.float32

        self.bin_mapper = RectilinearBinMapper(
            [list(numpy.arange(0.0, 10.1, 0.1))])
        self.bin_target_counts = numpy.empty((self.bin_mapper.nbins, ),
                                             numpy.int_)
        self.bin_target_counts[...] = 10
Esempio n. 7
0
    def initialize(self):
        self.pcoord_ndim = 1
        self.pcoord_len = pcoord_len
        self.pcoord_dtype = pcoord_dtype

        binbounds = [0.0] + np.arange(3.0, 8.1, 0.1).tolist() + [float('inf')]

        self.bin_mapper = RectilinearBinMapper([binbounds])
        self.bin_target_counts = np.empty((self.bin_mapper.nbins, ), np.int)
        self.bin_target_counts[...] = 12
Esempio n. 8
0
    def mapper_from_expr(self, expr):
        from westpa.binning import RectilinearBinMapper
        namespace = {'numpy': numpy, 'inf': float('inf')}

        try:
            return RectilinearBinMapper(eval(expr, namespace))
        except TypeError as e:
            if 'has no len' in str(e):
                raise ValueError(
                    'invalid bin boundary specification; you probably forgot to make a list of lists'
                )
Esempio n. 9
0
    def initialize(self):
        self.pcoord_ndim = 1
        self.pcoord_dtype = pcoord_dtype
        self.pcoord_len = pcoord_len

        #self.bin_mapper = RectilinearBinMapper([[0,1.3] + list(numpy.arange(1.4, 10.1, 0.1)) + [float('inf')]])
        self.bin_mapper = RectilinearBinMapper(
            [list(numpy.arange(0.0, 10.1, 0.1))])
        self.bin_target_counts = numpy.empty((self.bin_mapper.nbins, ),
                                             numpy.int_)
        self.bin_target_counts[...] = 10
Esempio n. 10
0
    def test_merge_by_weight(self):
        selected_counts = {0: 0, 1: 0}
        alpha = 0.01
        nrounds = 1000
        from scipy.stats import binom
        # lower and upper bounds of 95% CI for selecting the segment with weight 1/3
        lb = binom.ppf(alpha / 2.0, nrounds, 1.0 / 3.0)
        ub = binom.ppf(1.0 - alpha / 2.0, nrounds, 1.0 / 3.0)

        system = WESTSystem()
        system.bin_mapper = RectilinearBinMapper([[0.0, 1.0]])
        system.bin_target_counts = numpy.array([1])
        system.pcoord_len = 2
        self.we_driver = WEDriver(system=system)
        self.system = system
        self._seg_id = 0

        segments = [
            Segment(n_iter=1,
                    seg_id=0,
                    pcoord=numpy.array([[0], [0.25]], dtype=numpy.float32),
                    weight=1.0 / 3.0),
            Segment(n_iter=1,
                    seg_id=1,
                    pcoord=numpy.array([[0], [0.75]], dtype=numpy.float32),
                    weight=2.0 / 3.0)
        ]

        for _iround in xrange(nrounds):
            for segment in segments:
                segment.endpoint_type = Segment.SEG_ENDPOINT_UNSET

            self.we_driver.new_iteration()
            self.we_driver.assign(segments)
            self.we_driver.construct_next()

            assert len(self.we_driver.next_iter_binning[0]) == 1
            newseg = self.we_driver.next_iter_binning[0].pop()

            assert segments[
                newseg.
                parent_id].endpoint_type == Segment.SEG_ENDPOINT_CONTINUES
            assert segments[
                ~newseg.parent_id].endpoint_type == Segment.SEG_ENDPOINT_MERGED

            selected_counts[newseg.parent_id] += 1

        print(selected_counts)
        assert lb <= selected_counts[0] <= ub, (
            'Incorrect proportion of histories selected.'
            'this is expected about {:%} of the time; retry test.'.format(
                alpha))
Esempio n. 11
0
    def initialize(self):

        rc = self.rc.config['west', 'system']

        self.pcoord_ndim = 1
        self.pcoord_len = 2
        self.pcoord_dtype = pcoord_dtype
        self.target_count = rc.get('target_count')

        bin_bounds = [-float('inf')] + np.linspace(0.5, 2.5, 41).tolist() + [float('inf')]
        self.bin_mapper = RectilinearBinMapper([bin_bounds]) 
        self.bin_target_counts = np.zeros((len(bin_bounds),), dtype=np.int_)
        self.bin_target_counts[...] = self.target_count
Esempio n. 12
0
def mapper_from_expr(expr):
    namespace = {'numpy': numpy,
                 'inf': float('inf')}
    try:
        mapper = RectilinearBinMapper(eval(expr,namespace))
    except TypeError as e:
        if 'has no len' in str(e):
            raise ValueError('invalid bin boundary specification (a list of lists is required)')
        else:
            raise
    else:
        log.debug('loaded {!r} from expression {!r}'.format(mapper,expr))
        return mapper
Esempio n. 13
0
    def initialize(self):

        #   pcoord dimensionality and length. This should match your outside bin
        self.pcoord_ndim = 2
        self.pcoord_len = pcoordlength
        self.pcoord_dtype = pcoord_dtype

        #   These are your "outer" bins in both dimensions
        outer_mapper = RectilinearBinMapper([[0.00, numpy.inf],
                                             [0.00, 8.00, numpy.inf]])
        #   These define the "inner" adaptive bins. Each one indicates an independent
        #   adaptive binning scheme. Copy for more. Respects the parameters at the start.
        adaptive_mapper0 = FuncBinMapper(function_map,
                                         prod(binsperdim) + numberofdim *
                                         (2 + 2 * splitIsolated) +
                                         activetarget,
                                         kwargs={"multi_idx": 0})  # Bottom bin
        adaptive_mapper1 = FuncBinMapper(function_map,
                                         prod(binsperdim) + numberofdim *
                                         (2 + 2 * splitIsolated) +
                                         activetarget,
                                         kwargs={"multi_idx": 1})  # Top bin

        #   These are the bins where you'll place each adaptive scheme.
        self.bin_mapper = RecursiveBinMapper(outer_mapper)
        self.bin_mapper.add_mapper(adaptive_mapper0, [5, 1])  #Bottom mapper
        self.bin_mapper.add_mapper(adaptive_mapper1, [5, 10])  #Top mapper

        ######################### JL ##########################################
        #    This is the what the example looks like.
        #
        #   inf --------------------------------------------------------
        #      |                                                        |
        #      |                    adaptive_mapper1                    |
        #      |                                                        |
        #     8 --------------------------------------------------------
        #  D2  |        |                                               |
        #      | TARGET |           adaptive_mapper0                    |
        #      | STATE  |                                               |
        #     0 --------------------------------------------------------
        #              3.5(soft bound via mincap)                      inf
        #                        Dimension 1 of pcoord
        #
        #######################################################################

        self.bin_target_counts = numpy.empty((self.bin_mapper.nbins, ),
                                             dtype=numpy.int)

        #   Number of walkers per bin
        self.bin_target_counts[...] = bintargetcount
Esempio n. 14
0
 def initialize(self):
     self.pcoord_ndim = 2
     self.pcoord_len = 2
     self.pcoord_dtype = numpy.float32
     minfrag = 90
     outer_mapper = RectilinearBinMapper([[0, minfrag - 0.5,
                                           float('inf')], [0,
                                                           float('inf')]])
     binbounds1 = [1.0 * i - 0.5
                   for i in xrange(minfrag, 121)] + [float('inf')]
     binbounds2 = [15.0 * i * (i - 1) / 2
                   for i in xrange(1, 20)] + [float('inf')]
     self.bin_mapper = RecursiveBinMapper(outer_mapper)
     self.bin_mapper.add_mapper(
         RectilinearBinMapper([binbounds1, binbounds2]), [minfrag, 1])
     self.bin_target_counts = numpy.empty((self.bin_mapper.nbins, ),
                                          numpy.int)
     self.bin_target_counts[...] = 4
     #this is intended to change the bins where distance < 200 A to 16 simulations per bin
     for q1 in xrange(minfrag, 121):
         for q2 in [0.5 + 15.0 * i * (i - 1) / 2 for i in xrange(1, 8)]:
             print(q1, q2)
             bin = self.bin_mapper.assign(numpy.array([(q1, q2)]))  #tuple?
             self.bin_target_counts[bin] = 16
Esempio n. 15
0
    def initialize(self):
        """
        Initializes system
        """
        self.pcoord_ndim  = 1
        self.pcoord_len   = 6
        self.pcoord_dtype = numpy.float32
        binbounds         = [ 0.00, 2.80, 2.88, 3.00, 3.10, 3.29, 3.79, 3.94,
                              4.12, 4.39, 5.43, 5.90, 6.90, 7.90, 8.90, 9.90,
                             10.90,11.90,12.90,13.90,14.90,15.90,float('inf')]
        self.bin_mapper   = RectilinearBinMapper([binbounds])

        self.bin_target_counts      = numpy.empty((self.bin_mapper.nbins,),
                                        numpy.int)
        self.bin_target_counts[...] = 24
Esempio n. 16
0
    def initialize(self):
        self.pcoord_ndim = 1
        self.pcoord_len = pcoord_len
        self.pcoord_dtype = pcoord_dtype

        binbounds = [0.00, 1.0, 1.25, 1.5, 1.72, 2.0, 2.25, 2.5, 2.58, 2.65, 2.72, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4,
            3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.72, 3.75, 3.77, 3.8, 3.825, 3.85, 3.875, 3.9, 3.925, 3.95, 3.975, 4.0,
            4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.7, 4.8, 4.85, 4.9, 4.95, 5.0, 5.05,
            5.1, 5.18, 5.25, 5.3, 5.35, 5.4, 5.45, 5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4,
            6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 11.0, 11.5, 12.0, 12.5, 12.75, 13.0, 13.25, 13.5, 13.75, 14.0,
            14.5, 15.0, 15.5, 15.75, 16.0, 16.25, 16.5, 17.0, 17.3,  17.6, 18.0, 18.3, 18.6, 19.0, 19.5, 20, 'inf']

        self.bin_mapper = RectilinearBinMapper([binbounds])
        self.bin_target_counts = np.empty((self.bin_mapper.nbins,), np.int)
        self.bin_target_counts[...] = 10
Esempio n. 17
0
    def initialize(self):
        self.pcoord_ndim = 1
        self.pcoord_len = 11
        self.pcoord_dtype = numpy.float32
        self.dist_binbounds = [
            0.0, 0.2, 0.7, 1.5, 2.2, 3.8, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.6,
            12.0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
            float('inf')
        ]
        #self.dist_binbounds = [0.0,2.2,2.5,3.8,5.0,6.0,7.0,8.0,9.0,10.0,11.6,12.0,13,14,15,16,17,18,19,20,21,22,23,24,float('inf')]
        #self.dist_binbounds = [0.0,float('inf')]

        self.bin_mapper = RectilinearBinMapper([self.dist_binbounds])
        #self.bin_mapper = RectilinearBinMapper([self.dist_binbounds])
        self.bin_target_counts = numpy.empty((self.bin_mapper.nbins, ),
                                             numpy.int)
        self.bin_target_counts[...] = 8