Best Python code snippet using fMBT_python
relaxation_test.py
Source:relaxation_test.py
...27 msd = 4 * time * known_diffusion + offset28 diff, diff_err = relaxation.diffusion_constant(time, msd)29 assert np.isclose(diff, known_diffusion)30 assert np.isclose(diff_err, 0)31def test_exponential_relax():32 """Ensure the exponential_relaxation function working appropriately."""33 known_decay = 1e434 time = np.arange(100000)35 value = np.exp(-time / known_decay)36 relax, *_ = relaxation.exponential_relaxation(time, value)37 assert np.isclose(relax, known_decay)38@pytest.fixture39def linear_relax():40 num_values = 100041 time = np.arange(num_values)42 values = np.arange(num_values) / num_values43 return time, values44class TestThresholdRelaxation:45 def test_decay(self, linear_relax):46 time, values = linear_relax47 # This is to turn the linear growth into linear decay48 values = 1 - values49 logger.debug("Values: %s", values)50 relax, _ = relaxation.threshold_relaxation(51 time, values, threshold=0.5, decay=True52 )53 assert relax == len(time) / 2 + 1...
problem_3.py
Source:problem_3.py
1# import the code for the simulation2from simulator import Simulation3import matplotlib.pyplot as plt4import matplotlib5matplotlib.use("TkAgg")6import numpy as np7from time import time8plt.rc('font', family='serif')9plt.rcParams['text.usetex'] = False10fs = 1811# update various fontsizes to match12params = {'figure.figsize': (12, 8),13 'legend.fontsize': fs,14 'axes.labelsize': fs,15 'xtick.labelsize': 0.9 * fs,16 'ytick.labelsize': 0.9 * fs,17 'axes.linewidth': 1.1,18 'xtick.major.size': 7,19 'xtick.minor.size': 4,20 'ytick.major.size': 7,21 'ytick.minor.size': 4}22plt.rcParams.update(params)23def t_relax_analytic(N, size, radius, E, mass):24 n = N / size**225 sigma = radius * 226 v0 = np.sqrt(2 * E / mass)27 return (n * sigma * v0)**(-1)28def get_N_comparison(size=1000, radius=20, E=0.1, mass=1, repeats=10):29 start = time()30 N_range = np.array([25, 50, 75, 100, 125, 150, 175, 200])31 t_relax_list = []32 for N in N_range:33 t_relax = []34 for _ in range(repeats):35 sim = Simulation(N=N, E=E, size=size, radius=radius, masses=mass, visualise=False)36 t_relax.append(sim.run_simulation(run_until_steadystate=True))37 print("N =", N, "done", t_relax)38 t_relax_list.append(t_relax)39 np.save("data/t_relax_N.npy", t_relax_list)40 print("Runtime {:1.2f}s".format(time() - start))41 return N_range, t_relax_list42def get_r_comparison(N=100, size=1000, E=0.1, mass=1, repeats=10):43 start = time()44 r_range = np.array([10, 12.5, 15, 17.5, 20, 22.5, 25, 27.5, 30])45 t_relax_list = []46 for radius in r_range:47 t_relax = []48 for _ in range(repeats):49 sim = Simulation(N=N, E=E, size=size, radius=radius, masses=mass, visualise=False)50 t_relax.append(sim.run_simulation(run_until_steadystate=True))51 print("r =", radius, "done", t_relax)52 t_relax_list.append(t_relax)53 np.save("data/t_relax_r.npy", t_relax_list)54 print("Runtime {:1.2f}s".format(time() - start))55 return r_range, t_relax_list56def main():57 N = 10058 radius = 2059 size = 100060 E = 0.161 mass = 162 fig, axes = plt.subplots(1, 2, figsize=(18, 7))63 N_range, t_relax_N = get_N_comparison(radius=radius, size=size, E=E, mass=mass)64 r_range, t_relax_r = get_r_comparison(N=N, size=size, E=E, mass=mass)65 ax = axes[0]66 t_relax = t_relax_N67 N_range_smooth = np.linspace(N_range.min(), N_range.max(), 1000)68 ax.plot(N_range_smooth, t_relax_analytic(N_range_smooth, size, radius, E, mass) * 1.2,69 linestyle="dotted", lw=3, color=plt.get_cmap("plasma")(0.8),70 label=r"Analytic function, $X = 1.2$")71 ax.set_xlabel(r"Number of Particles")72 ax.set_ylabel(r"Relaxation Time, $\tau_{\rm relax} \, [\rm s]$")73 ax.errorbar(N_range, np.median(t_relax, axis=1), xerr=0.0,74 yerr=[np.median(t_relax, axis=1) - np.min(t_relax, axis=1),75 np.max(t_relax, axis=1) - np.median(t_relax, axis=1)],76 marker="o", color=plt.get_cmap("plasma")(0.2), label="Simulated results")77 ax.legend()78 ax = axes[1]79 t_relax = t_relax_r80 r_range_smooth = np.linspace(r_range.min(), r_range.max(), 1000)81 ax.plot(r_range_smooth, t_relax_analytic(N=N, size=size, radius=r_range_smooth, E=E, mass=mass) * 1.2,82 linestyle="dotted", lw=3, color=plt.get_cmap("plasma")(0.8),83 label=r"Analytic function, $X = 1.2$")84 ax.set_xlabel(r"Radius, $r \, [\rm cm]$")85 ax.set_ylabel(r"Relaxation Time, $\tau_{\rm relax} \, [\rm s]$")86 ax.errorbar(r_range, np.median(t_relax, axis=1), xerr=0.0,87 yerr=[np.median(t_relax, axis=1) - np.min(t_relax, axis=1),88 np.max(t_relax, axis=1) - np.median(t_relax, axis=1)],89 marker="o", color=plt.get_cmap("plasma")(0.2), label="Simulated results")90 ax.legend()91 plt.savefig("figures/3c.pdf", format="pdf", bbox_inches="tight")92 plt.show()93if __name__ == "__main__":...
relax.py
Source:relax.py
1import os2import yaml3import sys4import logging5def check_package(package_name,import_name):6 from importlib.util import find_spec7 has_lib = find_spec(package_name)8 if not has_lib:9 print("%s is not installed!!"%(import_name))10 return False11 12if __name__ == "__main__":13 package_list = {"biopython":"Bio","pandas":"pandas"}14 config_path = os.path.join(os.path.dirname(sys.argv[0]),"config.yaml")15 with open(config_path,"r") as f:16 config = yaml.load(f,Loader=yaml.FullLoader)17 #relax18 19 #score_jd220 if config["relax"]["need_prepare"]:21 cmd = os.path.join(os.path.dirname(sys.argv[0]),"jd2.run.sh") + " " +\22 config["input"]["path"] +" " +\23 os.path.join(config["input"]["rosetta_bin"],config["relax"]["score_jd2_exec"])24 ex = os.system(cmd)25 if ex:26 logging.error("run score_jd2 failed !")27 sys.exit(1)28 jd2_file = os.path.abspath(config["input"]["path"]) + "/jd2_pdb.list"29 else:30 jd2_file = config["input"]["path"]31 #if mpi_run relax32 if config["relax"]["mpi_run"]["use_mpi"]:33 mpi_cores = str(config["relax"]["mpi_run"]["mpi_cores"])34 else:35 mpi_cores = "0"36 #run relax37 cmd = os.path.join(os.path.dirname(sys.argv[0]),"relax.run.sh") + " " +\38 str(mpi_cores) + " " +\39 str(config["relax"]["relax_threads"])+ " " +\40 os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),config["relax"]["flag"])) + " " +\41 os.path.join(config["input"]["rosetta_bin"],config["relax"]["relax_exec"]) + " " +\42 jd2_file + " " +\43 config["input"]["path"]44 ex = os.system(cmd)45 if ex:46 logging.error("run relax failed !")47 sys.exit(1)48 relax_file = os.path.abspath(config["input"]["path"]) + "/relax_sc.list"49 could_flex = True50 51 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!