def singleWhamTramProf(unfiltered_data, umbrella_centers, force_constants, bins, minframes=500): ''' Given a series of umbrella timecourses, will extract the good data and run wham and tram on it. Note that if the Pymbar anaylsis shows that there are fewer than minframes good frames of data in a window, the last minframes frames from that window will be used, to ensure that we have umbrella coverage. This obviously should not be done for production PMFS (and I've seen a LOT of change to PMFs from dipping into this unequilibrated data) ''' series_quality = ee.analyze_group_of_time_series( unfiltered_data, identifiers=umbrella_centers) frameranges = [(np.min( (first, unfiltered_data[i].size - minframes)), 10000) for i, first in enumerate(series_quality.t0)] filtered_data = select_within_timecourse(unfiltered_data, frameranges) us_dtrajs = [assignToCenters(i, bins) for i in filtered_data] trammo = estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='dtram') whammo = estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='wham') return whammo, trammo
def param_scanning(unfiltered_data, force_constants, lags=(1, 2, 4, 8, 16, 32), iters=(5000, 10000, 20000, 40000, 80000, 200000)): ''' Scans tram parameters lag and maxiter to check for convergence of PMFS. Visualize results with plotProfs ''' series_quality = ee.analyze_group_of_time_series( unfiltered_data, identifiers=umbrella_centers) frameranges = [(np.min( (first, unfiltered_data[i].size - minframes)), 10000) for i, first in enumerate(series_quality.t0)] filtered_data = select_within_timecourse(unfiltered_data, frameranges) us_dtrajs = [assignToCenters(i, bins) for i in filtered_data] tram_by_lags = estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='dtram', lag=lags, maxiter=200000, maxerr=1.0E-10) tram_by_iters = [] for it in iters: tram_by_iters.append( estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='dtram', maxiter=it)) return tram_by_lags, tram_by_iters
def test_mbar(self): mbar = estimate_umbrella_sampling( self.us_trajs, self.us_dtrajs, self.us_centers, self.us_force_constants, md_trajs=self.md_trajs, md_dtrajs=self.md_dtrajs, maxiter=50000, maxerr=1e-13, estimator='mbar') validate_thermodynamics(self, mbar, strict=False) # not strict because out of global eq. check_serialization(mbar)
def test_wham_multi_lag(self): wham = estimate_umbrella_sampling( self.us_trajs, self.us_dtrajs, self.us_centers, self.us_force_constants, md_trajs=self.md_trajs, md_dtrajs=self.md_dtrajs, maxiter=100000, maxerr=1e-13, estimator='wham', lag=[1, 2]) validate_thermodynamics(self, wham, strict=False) # not strict because out of global eq. check_serialization(wham)
def test_tram(self): tram = estimate_umbrella_sampling( self.us_trajs, self.us_dtrajs, self.us_centers, self.us_force_constants, md_trajs=self.md_trajs, md_dtrajs=self.md_dtrajs, maxiter=10000, maxerr=1e-10, estimator='tram', lag=10) validate_thermodynamics(self, tram) validate_kinetics(self, tram)
def test_tram(self): tram = estimate_umbrella_sampling( self.us_trajs, self.us_dtrajs, self.us_centers, self.us_force_constants, md_trajs=self.md_trajs, md_dtrajs=self.md_dtrajs, maxiter=10000, maxerr=1e-10, estimator='tram', lag=10, connectivity='reversible_pathways') validate_thermodynamics(self, tram) validate_kinetics(self, tram) check_serialization(tram)
def test_wham(self): wham = estimate_umbrella_sampling(self.us_trajs, self.us_dtrajs, self.us_centers, self.us_force_constants, md_trajs=self.md_trajs, md_dtrajs=self.md_dtrajs, maxiter=100000, maxerr=1e-13, estimator='wham') validate_thermodynamics( self, wham, strict=False) # not strict because out of global eq.
def run_tram(trimmed_data, clust, ic): force = 119.503 force_list = [500] * len(trimmed_data) KT = 2.496 lag = 200 return thermo.estimate_umbrella_sampling(trimmed_data, clust.cluster.dtrajs, ic.center, force_list, kT=KT, maxiter=100000, maxerr=1.0E-4, dt_traj='10 ps', lag=lag, save_convergence_info=200, estimator='dtram')
def multipleTramProfs(unfiltered_data, umbrella_centers, force_constants, bins, numProfs, minframes=500, maxiter=200000, maxerr=1.0E-10): ''' computes multiple tram profiles, dividing each window into numProfs segments of size n / N Returns a list of individual tram profiles. Beware - if you don't have sufficient data points, one or more of these profiles could be wonky, and the tram.f may have fewer data points than you expect ''' series_quality = ee.analyze_group_of_time_series( unfiltered_data, identifiers=umbrella_centers) frameranges = [(np.min( (first, unfiltered_data[i].size - minframes)), 10000) for i, first in enumerate(series_quality.t0)] # get individual windows trams = [] chunk_sizes = [ int((len(unfiltered_data[i]) - framerange[0]) / numProfs) for i, framerange in enumerate(frameranges) ] for i in range(numProfs): chunked_framerange = [] for n, framerange in enumerate(frameranges): startframe = framerange[0] + i * chunk_sizes[n] endframe = startframe + chunk_sizes[n] chunked_framerange.append((startframe, endframe)) filtered_data = select_within_timecourse(unfiltered_data, chunked_framerange) us_dtrajs = [assignToCenters(i, bins) for i in filtered_data] trams.append( estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='dtram', maxiter=maxiter, maxerr=maxerr)) return trams
def test_umbrella_sampling_data(): req_keys = ('us_trajs', 'us_dtrajs', 'us_centers', 'us_force_constants', 'md_trajs', 'md_dtrajs', 'centers') us_data = get_umbrella_sampling_data() for key in us_data.keys(): assert key in req_keys for key in req_keys: assert key in us_data memm = estimate_umbrella_sampling(us_data['us_trajs'], us_data['us_dtrajs'], us_data['us_centers'], us_data['us_force_constants'], md_trajs=us_data['md_trajs'], md_dtrajs=us_data['md_dtrajs'], estimator='dtram', lag=5, maxiter=10000, maxerr=1.0E-14) assert memm.msm is not None memm.msm.pcca(2) pi = [memm.msm.pi[s].sum() for s in memm.msm.metastable_sets] assert_allclose(pi, [0.3, 0.7], rtol=0.25, atol=0.1)
def make_production_distance_pmf(directory, force_constants, suffix="nm.xvg", lag=30, maxerr=1.0E-10, maxiter=200000, umbrella_centers=np.arange(10, 40, 0.5), bins=np.arange(100, 40), reps=4): ''' Calculates a PMF and error for a data series specified in directory. Meant for distance series ''' umbrella_centers = [float(i) for i in umbrella_centers] unfiltered_data, dt = get_umbrella_data(directory, suffix, list(umbrella_centers), float) series_quality = ee.analyze_group_of_time_series( unfiltered_data, identifiers=umbrella_centers) frameranges = [(first, 10000) for i, first in enumerate(series_quality.t0)] filtered_data = select_within_timecourse(unfiltered_data, frameranges) us_dtrajs = [assignToCenters(i, bins) for i in filtered_data] trammo = estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='dtram', maxerr=maxerr, maxiter=maxiter) trammo_chunked = multipleTramProfs(unfiltered_data, umbrella_centers, force_constants, bins, reps, maxerr=maxerr, maxiter=maxiter) align_profs_deviation(trammo_chunked, trammo.f) standardErrors = standardError(trammo_chunked) return trammo.f, standardErrors
def make_production_angle_pmf(directory, force_constants, suffix="degrees.xvg", lag=30, maxerr=1.0E-10, maxiter=200000, umbrella_centers=np.arange(0, 91, 3), bins=np.arange(0, 91)): ''' Calculates a PMF and error for a data series specified in directory. This is meant for angular PMFs but could be adapted for distance PMFs without too much trouble ''' umbrella_centers = [float(i) for i in umbrella_centers] unfiltered_data, dt = get_umbrella_data(directory, suffix, list(umbrella_centers), int) series_quality = ee.analyze_group_of_time_series( unfiltered_data, identifiers=umbrella_centers) frameranges = [(first, 10000) for i, first in enumerate(series_quality.t0)] filtered_data = select_within_timecourse(unfiltered_data, frameranges) us_dtrajs = [assignToCenters(i, bins) for i in filtered_data] trammo = estimate_umbrella_sampling(filtered_data, us_dtrajs, umbrella_centers, force_constants, estimator='dtram', maxerr=maxerr, maxiter=maxiter) trammo_chunked = multipleTramProfs(unfiltered_data, umbrella_centers, force_constants, bins, 4, maxerr=maxerr, maxiter=maxiter) align_profs_deviation(trammo_chunked, trammo.f) standardErrors = standardError(trammo_chunked) return trammo.f, standardErrors
def test_exceptions(self): us_centers = [1.1, 1.3] us_force_constants = [1.0, 1.0] us_trajs = [ np.array([1.0, 1.1, 1.2, 1.1, 1.0, 1.1]), np.array([1.3, 1.2, 1.3, 1.4, 1.4, 1.3]) ] md_trajs = [ np.array([0.9, 1.0, 1.1, 1.2, 1.3, 1.4]), np.array([1.5, 1.4, 1.3, 1.4, 1.4, 1.5]) ] cluster = cluster_regspace(data=us_trajs + md_trajs, max_centers=10, dmin=0.15) us_dtrajs = cluster.dtrajs[:2] md_dtrajs = cluster.dtrajs[2:] # unmatching number of us trajectories / us parameters with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs[:-1], us_dtrajs, us_centers, us_force_constants) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs[:-1], us_centers, us_force_constants) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers[:-1], us_force_constants) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants[:-1]) # unmatching number of md trajectories with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants, md_trajs=md_trajs[:-1], md_dtrajs=md_dtrajs) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants, md_trajs=md_trajs, md_dtrajs=md_dtrajs[:-1]) # unmatchig trajectory lengths us_trajs_x = [ np.array([1.0, 1.1, 1.2, 1.1, 1.0]), np.array([1.3, 1.2, 1.3, 1.4, 1.4]) ] md_trajs_x = [ np.array([0.9, 1.0, 1.1, 1.2, 1.3]), np.array([1.5, 1.4, 1.3, 1.4, 1.4]) ] with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs_x, us_dtrajs, us_centers, us_force_constants) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants, md_trajs=md_trajs_x, md_dtrajs=md_dtrajs) # unmatching md_trajs/md_dtrajs cases with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants, md_trajs=None, md_dtrajs=md_dtrajs) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants, md_trajs=md_trajs, md_dtrajs=None) # single trajectory cases with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs[0], us_dtrajs[0], us_centers[0], us_force_constants[0]) with self.assertRaises(ValueError): estimate_umbrella_sampling(us_trajs, us_dtrajs, us_centers, us_force_constants, md_trajs=md_trajs[0], md_dtrajs=md_dtrajs[0])
temp2.append(np.expand_dims(i, axis=1)) new_traj = [i.copy(order='C') for i in temp2] D2 = [np.asarray(i, dtype=int, order='C') for i in D] force = 119.503 force_list = [500] * len(new_traj) KT = 2.496 lag = 200 center = np.arange(0.7, 15.5, 0.1).tolist() print('center is ', center) tram = thermo.estimate_umbrella_sampling(new_traj, D2, center, force_list, kT=KT, maxiter=500000, maxerr=5.0E-4, dt_traj='10 ps', lag=lag, save_convergence_info=200, estimator='dtram') print('tram f shape is ', len(tram.f)) pickle.dump(tram.f, open('tram_f_mix_3dim_5e4_3_try2.pickle', 'wb'), protocol=pickle.HIGHEST_PROTOCOL) pickle.dump(tram, open('tram_mix_3dim_e4_3_2try2.pickle', 'wb'), protocol=pickle.HIGHEST_PROTOCOL)
center = np.arange(0.7, 15.5, 0.1) center2 = center.tolist() colvar_list = [indir + "/comboCOLVAR{:2.1f}".format(i) for i in center] col = [np.loadtxt(f, skiprows=1) for f in colvar_list] length = len(center) print(length) force = 119.503 force_list = [500] * length ## Start doing stuff max_centers = 1500 dmin = 0.015 kt = 0.596 #cv = list(col[20000:,1]) cv = [i[20000::10, 1] for i in col] cv2 = [i.copy(order='C') for i in cv] us_cluster = coor.cluster_regspace(cv2, max_centers=max_centers, dmin=dmin) w = thermo.estimate_umbrella_sampling(cv2, us_cluster.dtrajs, center2, force_list, kT=2.496, maxiter=50000, lag=200, dt_traj='10 ps', save_convergence_info=200, estimator='dtram') pickle.dump(us_cluster, open(clust_out, 'wb')) pickle.dump(w, open(out, 'wb'))