diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c417682..a4a2ea1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ To contribute to the pyMBE library, first one needs to be added as a member of t If you want to contribute to the development of the pyMBE library, please contact Dr. Pablo M. Blanco (pablb@ntnu.no) ## Rules to contribute to pyMBE -Any new version of the code must reproduce all the data stored in `reference_data/`. -The scripts provided in `tests/` can be used to quickly set-up simulations with pyMBE to reproduce such data sets. +Any new version of the code must reproduce all the data stored in `testsuite/data`. +The scripts provided in `testsuite/` and in `samples/Beyer2024`can be used to quickly set-up simulations with pyMBE to reproduce such data sets. All new code will be reviewed by at least one member of the pyMBE development team before being merged into the stable version of the library to ensure that a functional version of the code is always available. Class methods are sorted in alphabetical order. diff --git a/README.md b/README.md index 459b631..395786a 100644 --- a/README.md +++ b/README.md @@ -20,17 +20,19 @@ A deprecated version of pyMBE compatible with ESPResSo v4.1.4 (under the histori - `docs/`: folder with the API documentation of pyMBE. - `figs/`: folder with various images used in the tutorials of pyMBE. -- `handy_scripts/`: folder with various handy scripts and libraries. +- `libs/`: folder with various libraries. - `logo/`: folder with the logo of pyMBE. +- `mantainer/`: folder with various scripts used by the mantainers. - `parameters/`: folder with various sets of parameters from previous works. - `samples/`: folder with various sample scripts showcasing how to use pyMBE to setup different systems. -- `tests/`: folder with several test scripts and data to check that new developments do not break pyMBE. +- `testsuite/`: folder with several test scripts and data for continous integration of the library. - `tutorials/`: folder with the available tutorials on pyMBE. - `visualization/`: folder with helper scripts to aid the visualization of vtf trajectories from constant pH and Grand reaction simulations with [VMD](https://www.ks.uiuc.edu/Research/vmd/).6 - `AUTHORS.md`: list of authors and contributors of pyMBE. - `CONTRIBUTING`: rules on how to contribute to pyMBE. - `LICENSE.md`: license of pyMBE. - `pyMBE.py`: source code of pyMBE +- `requierements.txt`: list of requiered libraries to use pyMBE. ## Usage diff --git a/lib/analysis.py b/lib/analysis.py index f2ed1c5..1b69a25 100644 --- a/lib/analysis.py +++ b/lib/analysis.py @@ -50,7 +50,7 @@ def analyze_time_series(path_to_datafolder): index_list=[] for key in data_dict.keys(): value_list.append(data_dict[key]) - index_list.append((key,)) + index_list.append((key,"value")) analyzed_data = pd.concat([pd.Series(value_list, index=index_list), analyzed_data]) data = add_data_to_df(df=data, data_dict=analyzed_data.to_dict(), diff --git a/samples/Beyer2024/peptide.py b/samples/Beyer2024/peptide.py index 1fef3a7..56fbc5f 100644 --- a/samples/Beyer2024/peptide.py +++ b/samples/Beyer2024/peptide.py @@ -50,17 +50,7 @@ if mode not in valid_modes: raise ValueError(f"Mode {mode} is not currently supported, valid modes are {valid_modes}") -# Simulation parameters -if mode == "short-run": - Nsamples = 1000 - MD_steps_per_sample = 1000 -elif mode == "long-run": - Nsamples = 5000 - MD_steps_per_sample = 5000 -elif mode == "test": - Nsamples = 500 - MD_steps_per_sample = 700 SEED = 100 dt = 0.01 @@ -96,6 +86,22 @@ diameter_Cl=0.36*pmb.units.nm chain_length=len(sequence) +# Simulation parameters +if mode == "short-run": + Nsamples = 1000 + MD_steps_per_sample = 1000 +elif mode == "long-run": + Nsamples = 5000 + MD_steps_per_sample = 5000 +elif mode == "test": + Nsamples = 500 + MD_steps_per_sample = 700 + c_salt = 5e-3 * pmb.units.mol/ pmb.units.L + N_peptide_chains = 1 +else: + raise RuntimeError() + + pmb.define_peptide (name=sequence, sequence=sequence, model=model) # Solution parameters diff --git a/testsuite/peptide_tests.py b/testsuite/peptide_tests.py index 2399692..15373b2 100644 --- a/testsuite/peptide_tests.py +++ b/testsuite/peptide_tests.py @@ -8,7 +8,7 @@ # Template of the test -def run_peptide_test(script_path,test_pH_values,sequence,rtol,atol): +def run_peptide_test(script_path,test_pH_values,sequence,rtol,atol,mode="test"): """ Runs a set of tests for a given peptide sequence. @@ -17,10 +17,14 @@ def run_peptide_test(script_path,test_pH_values,sequence,rtol,atol): test_pH_values(`lst`): List of pH values to be tested. sequence(`str`): Amino acid sequence of the peptide. """ + valid_modes=["test","save"] + if mode not in valid_modes: + raise ValueError(f"Mode {mode} not supported, valid modes: {valid_modes}") # Get data folder time_series_folder_path=pmb.get_resource(f"samples/Beyer2024/time_series") # clean up data folder - os.system(f"rm {time_series_folder_path}/*") + if len(os.listdir(time_series_folder_path)): + os.system(f"rm {time_series_folder_path}/*") print(f"Running tests for {sequence}") for pH in (pbar := tqdm(test_pH_values)): pbar.set_description(f"pH = {pH}") @@ -29,19 +33,28 @@ def run_peptide_test(script_path,test_pH_values,sequence,rtol,atol): os.system(run_command) # Analyze all time series data=analysis.analyze_time_series(path_to_datafolder=time_series_folder_path) - # Get reference test data data_path=pmb.get_resource(path="testsuite/peptide_tests_data") - ref_data=pd.read_csv(data_path+f"/{sequence}.csv", header=[0, 1], index_col=0) - # Check that the charge and radius of gyration are consistent - np.testing.assert_allclose(data["mean","charge"].to_numpy(), - ref_data["mean","charge"].to_numpy(), - rtol=rtol, - atol=atol) - np.testing.assert_allclose(data["mean","rg"].to_numpy(), - ref_data["mean","rg"].to_numpy(), - rtol=rtol, - atol=atol) - print(f"Test for {sequence} succesful") + if mode == "test": + # Get reference test data + ref_data=pd.read_csv(data_path+f"/{sequence}.csv", header=[0, 1]) + # Check charge + test_charge=np.sort(data["mean","charge"].to_numpy()) + ref_charge=np.sort(ref_data["mean","charge"].to_numpy()) + # Check that the charge and radius of gyration are consistent + np.testing.assert_allclose(test_charge, + ref_charge, + rtol=rtol, + atol=atol) + np.testing.assert_allclose(data["mean","rg"].to_numpy(), + ref_data["mean","rg"].to_numpy(), + rtol=rtol, + atol=atol) + print(f"Test for {sequence} succesful") + elif mode == "save": + # Save data for future testing + data.to_csv(f"{data_path}/{sequence}.csv", index=False) + else: + raise RuntimeError # Create an instance of pyMBE library pmb = pyMBE.pymbe_library() diff --git a/testsuite/peptide_tests_data/EEEEEHHHHH.csv b/testsuite/peptide_tests_data/EEEEEHHHHH.csv index a2c1b9b..2029cbc 100644 --- a/testsuite/peptide_tests_data/EEEEEHHHHH.csv +++ b/testsuite/peptide_tests_data/EEEEEHHHHH.csv @@ -1,5 +1,5 @@ pH,sequence,n_blocks,block_size,mean,mean,err_mean,err_mean,n_eff,n_eff,tau_int,tau_int -nan,nan,nan,nan,charge,rg,charge,rg,charge,rg,charge,rg -7,EEEEEHHHHH,16.0,28.125,-3.46,2.2703462218107697,0.08485448511846783,0.011270236960158787,29.626400298799958,123.97658163444471,53.16204412785421,12.704012155120516 -3,EEEEEHHHHH,16.0,28.125,3.6155555555555554,2.2852353902531646,0.0659070291966048,0.00965865997785087,36.01484582149586,171.5617117303853,43.73196564107516,9.18037004963811 -11,EEEEEHHHHH,16.0,28.125,-5.0,2.376694528257385,0.0,0.009075495803215277,,180.56146365212345,,8.722791498127924 +value,value,nan,nan,charge,rg,charge,rg,charge,rg,charge,rg +3,EEEEEHHHHH,16.0,28.125,3.74,2.2930545511345084,0.09668283176667573,0.012248005496732568,63.9924303361178,386.504157031771,24.61228604323432,4.074988512749192 +7,EEEEEHHHHH,16.0,28.125,-3.462222222222222,2.282215370136204,0.08152363902529337,0.02392826711272775,107.85755044145347,125.10472480386765,14.602593824798644,12.589452576659077 +11,EEEEEHHHHH,16.0,28.125,-5.0,2.379941392407537,0.0,0.015862071975736733,,271.3603994805873,,5.804089333038255 diff --git a/testsuite/peptide_tests_data/KKKKKDDDDD.csv b/testsuite/peptide_tests_data/KKKKKDDDDD.csv index ad81080..8a89941 100644 --- a/testsuite/peptide_tests_data/KKKKKDDDDD.csv +++ b/testsuite/peptide_tests_data/KKKKKDDDDD.csv @@ -1,5 +1,5 @@ pH,sequence,n_blocks,block_size,mean,mean,err_mean,err_mean,n_eff,n_eff,tau_int,tau_int -nan,nan,nan,nan,charge,rg,charge,rg,charge,rg,charge,rg -11,KKKKKDDDDD,16.0,28.125,-2.4394444444444443,2.2049612765357924,0.0715700444086051,0.012580800325214478,36.920026395901495,97.521880100548,42.65977448513195,16.150221862113444 -7,KKKKKDDDDD,16.0,28.125,0.0,2.0725310670590007,0.0,0.004655049123372929,,485.26077729437475,,3.2456775278971928 -3,KKKKKDDDDD,16.0,28.125,2.7888888888888888,2.2437294343122227,0.10015636535927931,0.009715071564187647,23.660790449758085,160.02409606208622,66.56582346133663,9.842267750871764 +value,value,nan,nan,charge,rg,charge,rg,charge,rg,charge,rg +3,KKKKKDDDDD,16.0,28.125,2.92,2.24224133500218,0.10683895616817528,0.016899080996828193,66.55820017221221,218.86820380470385,23.66350045462667,7.196111507542911 +7,KKKKKDDDDD,16.0,28.125,0.0022222222222222222,2.061724695770055,0.002305347229885367,0.010022432237558167,418.13333333333344,337.82731077353264,3.7667410715105456,4.662145273062604 +11,KKKKKDDDDD,16.0,28.125,-2.537777777777778,2.2240114798138597,0.09417150320822036,0.016801648569199405,91.37898210342641,223.8836649942004,17.235910969676027,7.034903596361424 diff --git a/testsuite/peptide_tests_data/nDSHAKRHHGYKRKFHEKHHSHRGYc.csv b/testsuite/peptide_tests_data/nDSHAKRHHGYKRKFHEKHHSHRGYc.csv index 677c803..743f138 100644 --- a/testsuite/peptide_tests_data/nDSHAKRHHGYKRKFHEKHHSHRGYc.csv +++ b/testsuite/peptide_tests_data/nDSHAKRHHGYKRKFHEKHHSHRGYc.csv @@ -1,5 +1,5 @@ pH,sequence,n_blocks,block_size,mean,mean,err_mean,err_mean,n_eff,n_eff,tau_int,tau_int -nan,nan,nan,nan,charge,rg,charge,rg,charge,rg,charge,rg -11,nDSHAKRHHGYKRKFHEKHHSHRGYc,16.0,28.125,-1.191111111111111,4.063464427616705,0.05348160750422651,0.08851343132097834,251.94488535923495,72.1482798903042,6.251367229735849,21.83004227445118 -7,nDSHAKRHHGYKRKFHEKHHSHRGYc,16.0,28.125,4.997777777777777,4.20850730205197,0.045342906001995156,0.11132315378572168,215.56745024938866,55.258072529405915,7.306297858105055,28.50262283752534 -3,nDSHAKRHHGYKRKFHEKHHSHRGYc,16.0,28.125,12.657777777777778,5.2393962478267655,0.060622215668095406,0.11362578274313505,161.98895235804122,60.20523413647287,9.722885277713772,26.160516151537188 +value,value,nan,nan,charge,rg,charge,rg,charge,rg,charge,rg +7,nDSHAKRHHGYKRKFHEKHHSHRGYc,16.0,28.125,5.044444444444444,4.279252793720242,0.05798349244388049,0.09771700380997232,155.74642000226976,71.28000135030244,10.112591994161557,22.095959177862643 +3,nDSHAKRHHGYKRKFHEKHHSHRGYc,16.0,28.125,12.642222222222221,5.277371251802207,0.046374949253443896,0.11404609215228863,287.2696477457004,55.72484859428179,5.482653710177252,28.26387221796589 +11,nDSHAKRHHGYKRKFHEKHHSHRGYc,16.0,28.125,-1.1377777777777778,3.925277367120465,0.046895855319717836,0.0915024823081239,297.1873784737742,63.15113924203325,5.299686709855564,24.940167650783412