From cf6e4294959158c5f978f42f5c500fd4a68da466 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:42:22 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/_images/mosdef_dihedral_fit_license | 2 +- docs/environment_docs.yml | 1 - ...dral_with_Gaussian_and_write_all_files.rst | 1 - .../quick_start/gomc_examples_repository.rst | 1 - .../citing_mosdef_dihedral_fit_python.rst | 1 - docs/reference/user_notices.rst | 2 +- mosdef_dihedral_fit/__init__.py | 5 +- .../dihedral_fit/fit_dihedral_with_gomc.py | 1211 +++--- .../tests/test_fit_dihedral_with_gomc.py | 3609 ++++++++++------- .../tests/test_math_operation.py | 224 +- .../utils/file_read_and_write.py | 995 +++-- mosdef_dihedral_fit/utils/io.py | 4 +- mosdef_dihedral_fit/utils/math_operations.py | 466 ++- 13 files changed, 3962 insertions(+), 2560 deletions(-) diff --git a/docs/_images/mosdef_dihedral_fit_license b/docs/_images/mosdef_dihedral_fit_license index 4dca69e..12751d9 100644 --- a/docs/_images/mosdef_dihedral_fit_license +++ b/docs/_images/mosdef_dihedral_fit_license @@ -31,4 +31,4 @@ The **vmd-python** software is licensed by the Theoretical and Computational Bio The vmd-python website is https://github.com/Eigenstate/vmd-python -The official VMD web page is http://www.ks.uiuc.edu/Research/vmd \ No newline at end of file +The official VMD web page is http://www.ks.uiuc.edu/Research/vmd diff --git a/docs/environment_docs.yml b/docs/environment_docs.yml index 8bfdd0a..9d20335 100644 --- a/docs/environment_docs.yml +++ b/docs/environment_docs.yml @@ -21,4 +21,3 @@ dependencies: - sphinxcontrib-svg2pdfconverter - sphinxcontrib-video - sphinxcontrib-serializinghtml - diff --git a/docs/getting_started/quick_start/fit_a_dihedral_with_Gaussian_and_write_all_files.rst b/docs/getting_started/quick_start/fit_a_dihedral_with_Gaussian_and_write_all_files.rst index 19be92a..179b509 100644 --- a/docs/getting_started/quick_start/fit_a_dihedral_with_Gaussian_and_write_all_files.rst +++ b/docs/getting_started/quick_start/fit_a_dihedral_with_Gaussian_and_write_all_files.rst @@ -169,4 +169,3 @@ Run the dihedral fit to fit to the MM simulations: fit_min_validated_r_squared=0.99, fit_validation_r_squared_rtol=5e-03 ) - diff --git a/docs/getting_started/quick_start/gomc_examples_repository.rst b/docs/getting_started/quick_start/gomc_examples_repository.rst index d517a0b..c629db0 100644 --- a/docs/getting_started/quick_start/gomc_examples_repository.rst +++ b/docs/getting_started/quick_start/gomc_examples_repository.rst @@ -9,4 +9,3 @@ Simple Examples with it's directory/path specified in the dihedral fit function. `Simple MoSDeF-dihedral-fit examples `_ are provided on the **GOMC** Github page. - diff --git a/docs/reference/citing_mosdef_dihedral_fit_python.rst b/docs/reference/citing_mosdef_dihedral_fit_python.rst index 754e560..daab4ef 100644 --- a/docs/reference/citing_mosdef_dihedral_fit_python.rst +++ b/docs/reference/citing_mosdef_dihedral_fit_python.rst @@ -59,4 +59,3 @@ Please also cite the following software: * `Visual Molecular Dynamics (VMD) `_ * `vmd-python `_ - diff --git a/docs/reference/user_notices.rst b/docs/reference/user_notices.rst index 7acb583..528a922 100644 --- a/docs/reference/user_notices.rst +++ b/docs/reference/user_notices.rst @@ -12,4 +12,4 @@ There are some critical items to complete and consider when using the **MoSDeF-d #. The mixing/combining rules and 1-4 non-bonded dihedral interactions are in the **MoSDeF** XML file and will automatically be input into **GOMC**, the Molecular Mechanics (MM) engine, so please be sure these are entered properly in the XML file or it may set the default parameters, which will produce a wrong result. - #. The atomic order and molecule must exactly match for the user inputted `Gaussian `_ log files and the **mol2** file. There are checks to ensure that the same elements and the number of atoms are used, but there is no simple way to determine if the atoms are out of order when these criteria match. Therefore, it is up to the user to ensure these are the same. It is recommended that the user create the **mol2** and use its elements and coordinates to set up the **Gaussian** simulation, as this will reduce the chance of errors. \ No newline at end of file + #. The atomic order and molecule must exactly match for the user inputted `Gaussian `_ log files and the **mol2** file. There are checks to ensure that the same elements and the number of atoms are used, but there is no simple way to determine if the atoms are out of order when these criteria match. Therefore, it is up to the user to ensure these are the same. It is recommended that the user create the **mol2** and use its elements and coordinates to set up the **Gaussian** simulation, as this will reduce the chance of errors. diff --git a/mosdef_dihedral_fit/__init__.py b/mosdef_dihedral_fit/__init__.py index b727b96..ee38d51 100644 --- a/mosdef_dihedral_fit/__init__.py +++ b/mosdef_dihedral_fit/__init__.py @@ -1,5 +1,6 @@ """ MoSDeF-dihedral-fit: A simple software package to fit dihedrals using the MoSDeF.""" -from mosdef_dihedral_fit.dihedral_fit.fit_dihedral_with_gomc import fit_dihedral_with_gomc - +from mosdef_dihedral_fit.dihedral_fit.fit_dihedral_with_gomc import ( + fit_dihedral_with_gomc, +) __version__ = "0.0.0" diff --git a/mosdef_dihedral_fit/dihedral_fit/fit_dihedral_with_gomc.py b/mosdef_dihedral_fit/dihedral_fit/fit_dihedral_with_gomc.py index 8067f63..fe7b83e 100755 --- a/mosdef_dihedral_fit/dihedral_fit/fit_dihedral_with_gomc.py +++ b/mosdef_dihedral_fit/dihedral_fit/fit_dihedral_with_gomc.py @@ -1,43 +1,43 @@ +import math import os import shutil -import pandas as pd -import numpy as np -import mbuild as mb import subprocess -import unyt as u -from unyt.dimensions import angle, energy, length, temperature +import warnings +from warnings import warn + +import matplotlib.pyplot as plt +import mbuild as mb import mosdef_gomc.formats.gmso_charmm_writer as mf_charmm import mosdef_gomc.formats.gmso_gomc_conf_writer as gomc_control -import matplotlib.pyplot as plt -import math - -from scipy.optimize import curve_fit +import numpy as np +import pandas as pd +import unyt as u from mbuild.utils.conversion import OPLS_to_RB from mosdef_gomc.utils.conversion import OPLS_to_periodic +from scipy.optimize import curve_fit +from unyt.dimensions import angle, energy, length, temperature import mosdef_dihedral_fit.utils.file_read_and_write as mdf_frw import mosdef_dihedral_fit.utils.math_operations as mdf_math -import warnings -from warnings import warn -warnings.filterwarnings('ignore') +warnings.filterwarnings("ignore") def fit_dihedral_with_gomc( - fit_dihedral_atom_types, - mol2_selection, - forcefield_selection, - temperature_unyt_units, - gomc_binary_path, - qm_log_files_and_entries_to_remove_dict, - manual_dihedral_atom_numbers_list=None, - zeroed_dihedral_atom_types=None, - qm_engine="gaussian", - VDWGeometricSigma=None, - atom_type_naming_style='general', - gomc_cpu_cores=1, - fit_min_validated_r_squared=0.98, - fit_validation_r_squared_rtol=2.5e-02 + fit_dihedral_atom_types, + mol2_selection, + forcefield_selection, + temperature_unyt_units, + gomc_binary_path, + qm_log_files_and_entries_to_remove_dict, + manual_dihedral_atom_numbers_list=None, + zeroed_dihedral_atom_types=None, + qm_engine="gaussian", + VDWGeometricSigma=None, + atom_type_naming_style="general", + gomc_cpu_cores=1, + fit_min_validated_r_squared=0.98, + fit_validation_r_squared_rtol=2.5e-02, ): """Fit the desired dihedral to a MM force field, based on QM data. @@ -494,42 +494,54 @@ def fit_dihedral_with_gomc( """ # check if 'mol2_selection' file is correct format if not isinstance(mol2_selection, str): - raise TypeError("ERROR: Please enter mol2 file ('mol2_selection') as a string.") + raise TypeError( + "ERROR: Please enter mol2 file ('mol2_selection') as a string." + ) extension_ff_name = os.path.splitext(mol2_selection)[-1] if extension_ff_name != ".mol2": raise ValueError( - "ERROR: Please enter enter mol2 file ('mol2_selection') name with the .mol2 extension.") + "ERROR: Please enter enter mol2 file ('mol2_selection') name with the .mol2 extension." + ) if not os.path.exists(mol2_selection): - raise ValueError(f"ERROR: The {mol2_selection} file ('mol2_selection') does not exists.") + raise ValueError( + f"ERROR: The {mol2_selection} file ('mol2_selection') does not exists." + ) # check if 'forcefield_selection' file is correct format if not isinstance(forcefield_selection, str): - raise TypeError("ERROR: Please enter xml file ('forcefield_selection') as a string.") + raise TypeError( + "ERROR: Please enter xml file ('forcefield_selection') as a string." + ) extension_ff_name = os.path.splitext(forcefield_selection)[-1] if extension_ff_name != ".xml": raise ValueError( - "ERROR: Please enter enter xml file ('forcefield_selection') name with the .xml extension.") + "ERROR: Please enter enter xml file ('forcefield_selection') name with the .xml extension." + ) if not os.path.exists(forcefield_selection): - raise ValueError(f"ERROR: The {forcefield_selection} file ('forcefield_selection') does not exists.") - + raise ValueError( + f"ERROR: The {forcefield_selection} file ('forcefield_selection') does not exists." + ) - if qm_engine == "gaussian" and manual_dihedral_atom_numbers_list is not None: + if ( + qm_engine == "gaussian" + and manual_dihedral_atom_numbers_list is not None + ): warn( "WARNING: When reading the qm_engine = 'gaussian' files, the " "'manual_dihedral_atom_numbers_list' is set to None, and will not be used, " "because the the gaussian log files already contain this information." - ) + ) manual_dihedral_atom_numbers_list = None # test the temperature_unyt_units input print_error_value = f"ERROR: The 'temperature_unyt_units' is not temperature of type {type(u.unyt_quantity)}." if isinstance(temperature_unyt_units, u.unyt_quantity): if temperature == temperature_unyt_units.units.dimensions: - temperature_unyt_units =temperature_unyt_units.to("K") + temperature_unyt_units = temperature_unyt_units.to("K") else: raise ValueError(print_error_value) @@ -539,13 +551,12 @@ def fit_dihedral_with_gomc( # test the qm_log_files_and_entries_to_remove_dict input print_error_value = ( - "ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - "with a string keys and list of int>=0 as the values. Example: " + "ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + "with a string keys and list of int>=0 as the values. Example: " "{'path/HC_CT_CT_HC_part_1.log'): [], 'path/HC_CT_CT_HC_part_2.log'): [0, 5]}" ) if isinstance(qm_log_files_and_entries_to_remove_dict, dict): for key_j, value_j in qm_log_files_and_entries_to_remove_dict.items(): - if isinstance(key_j, str): if not os.path.exists(key_j): raise ValueError( @@ -555,8 +566,8 @@ def fit_dihedral_with_gomc( else: raise TypeError(print_error_value) - print('*****************') - print(f'value_j = {str(value_j)}') + print("*****************") + print(f"value_j = {str(value_j)}") if isinstance(value_j, list): for int_j in value_j: if not isinstance(int_j, int) or int_j < 0: @@ -570,7 +581,9 @@ def fit_dihedral_with_gomc( # check if 'gomc_binary_path' leads to the file is correct format GOMC_CPU_NVT if not isinstance(gomc_binary_path, str): - raise TypeError("ERROR: Please enter the 'gomc_binary_path' file as a string.") + raise TypeError( + "ERROR: Please enter the 'gomc_binary_path' file as a string." + ) if not os.path.exists(f"{gomc_binary_path}/{'GOMC_CPU_NVT'}"): raise ValueError( @@ -586,7 +599,7 @@ def fit_dihedral_with_gomc( if isinstance(zeroed_dihedral_atom_types, (list, type(None))): if isinstance(zeroed_dihedral_atom_types, list): for list_j in zeroed_dihedral_atom_types: - if isinstance(list_j, list) and len(list_j)==4: + if isinstance(list_j, list) and len(list_j) == 4: for str_j in list_j: if not isinstance(str_j, str): raise TypeError(print_error_value) @@ -613,11 +626,13 @@ def fit_dihedral_with_gomc( # test the 'fit_min_validated_r_squared' input if isinstance(fit_min_validated_r_squared, float): - if not (fit_min_validated_r_squared>0 and fit_min_validated_r_squared<1): + if not ( + fit_min_validated_r_squared > 0 and fit_min_validated_r_squared < 1 + ): raise ValueError( f"ERROR: The 'fit_min_validated_r_squared'= {fit_min_validated_r_squared}, " f"but it must be a 00 and fit_validation_r_squared_rtol<1): + if not ( + fit_validation_r_squared_rtol > 0 + and fit_validation_r_squared_rtol < 1 + ): raise ValueError( f"ERROR: The 'fit_validation_r_squared_rtol' = {fit_validation_r_squared_rtol}, " - f"but it must be a 0 0." ) @@ -651,18 +670,18 @@ def fit_dihedral_with_gomc( ) # check values write the qm data files data out - if isinstance(qm_engine , str): + if isinstance(qm_engine, str): if qm_engine == "gaussian": mdf_frw.write_qm_data_files( qm_log_files_and_entries_to_remove_dict, manual_dihedral_atom_numbers_list=manual_dihedral_atom_numbers_list, - qm_engine=qm_engine + qm_engine=qm_engine, ) elif qm_engine == "gaussian_style_final_files": mdf_frw.write_qm_data_files( qm_log_files_and_entries_to_remove_dict, manual_dihedral_atom_numbers_list=manual_dihedral_atom_numbers_list, - qm_engine=qm_engine + qm_engine=qm_engine, ) else: @@ -696,7 +715,7 @@ def fit_dihedral_with_gomc( # ************************************************************** # delete existing make a gomc simulation folder ('GOMC_simulations') and move there - gomc_runs_folder_name = 'GOMC_simulations' + gomc_runs_folder_name = "GOMC_simulations" if os.path.isdir(gomc_runs_folder_name): shutil.rmtree(gomc_runs_folder_name) @@ -706,14 +725,16 @@ def fit_dihedral_with_gomc( gomc_raw_energy_filename = "gomc_raw_energies_in_Kelvin.txt" # The combined GOMC and Gaussian dihedral angles and energies in kcal/mol - gomc_gaussian_kcal_mol_energy_filename = "all_normalized_energies_in_kcal_per_mol.txt" + gomc_gaussian_kcal_mol_energy_filename = ( + "all_normalized_energies_in_kcal_per_mol.txt" + ) - output_gomc_pdb_psf_ff_file_name_str = f'GOMC_pdb_psf_ff_files' + output_gomc_pdb_psf_ff_file_name_str = f"GOMC_pdb_psf_ff_files" seed_no = 12345 # load bis(ethylhexylamido) with Gd fragment = mb.load(mol2_selection, smiles=False) - fragment.name = 'TMP' + fragment.name = "TMP" residues_list = [fragment.name] fix_residues = None @@ -723,42 +744,59 @@ def fit_dihedral_with_gomc( # liquid_box_0_length_nm must be a value <= 999.8 nm and an interger value in angstroms <= 9998 Ang liquid_box_0_length_nm = 999.8 - print("INFO: Started Building the fragment for the GOMC simulation with dihedral k values = 0") + print( + "INFO: Started Building the fragment for the GOMC simulation with dihedral k values = 0" + ) box_0_liq = mb.fill_box( compound=[fragment], n_compounds=[1], - box=[liquid_box_0_length_nm, liquid_box_0_length_nm, liquid_box_0_length_nm], + box=[ + liquid_box_0_length_nm, + liquid_box_0_length_nm, + liquid_box_0_length_nm, + ], seed=seed_no, ) - print("INFO: Finished Building the fragment for the GOMC simulation with dihedral k values = 0") + print( + "INFO: Finished Building the fragment for the GOMC simulation with dihedral k values = 0" + ) - print("INFO: Started Building the Charmm Object for the GOMC simulation with dihedral k values = 0") + print( + "INFO: Started Building the Charmm Object for the GOMC simulation with dihedral k values = 0" + ) # build the charmm object - charmm = mf_charmm.Charmm(box_0_liq, - f'{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}', - structure_box_1=None, - filename_box_1=None, - ff_filename=f'{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_per_xml', - forcefield_selection=forcefield_selection, - residues=residues_list, - bead_to_atom_name_dict=None, - fix_residue=fix_residues, - fix_residue_in_box=fix_residue_in_box, - gomc_fix_bonds_angles=None, - atom_type_naming_style=atom_type_naming_style - ) - print("INFO: Finished Building the Charmm Object for the GOMC simulation with dihedral k values = 0") + charmm = mf_charmm.Charmm( + box_0_liq, + f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}", + structure_box_1=None, + filename_box_1=None, + ff_filename=f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_per_xml", + forcefield_selection=forcefield_selection, + residues=residues_list, + bead_to_atom_name_dict=None, + fix_residue=fix_residues, + fix_residue_in_box=fix_residue_in_box, + gomc_fix_bonds_angles=None, + atom_type_naming_style=atom_type_naming_style, + ) + print( + "INFO: Finished Building the Charmm Object for the GOMC simulation with dihedral k values = 0" + ) # Write the write the FF (.inp), psf, pdb, and GOMC control files - print("INFO: Started Writing the PDB, PSF, and FF files for the GOMC simulation with dihedral k values = 0") + print( + "INFO: Started Writing the PDB, PSF, and FF files for the GOMC simulation with dihedral k values = 0" + ) charmm.write_inp() charmm.write_psf() charmm.write_pdb() - print("INFO: Finished Writing the PDB, PSF, and FF files for the GOMC simulation with dihedral k values = 0") + print( + "INFO: Finished Writing the PDB, PSF, and FF files for the GOMC simulation with dihedral k values = 0" + ) # ************************************************************** # make the PDB, PSF and FF files for all the dihedral angles (END) @@ -768,8 +806,8 @@ def fit_dihedral_with_gomc( # make the GOMC control file with the selected dihedral angles set to zero (START) # ************************************************************** mdf_frw.change_gomc_ff_file_dihedral_values( - f'{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_per_xml.inp', - f'{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_zeroed.inp', + f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_per_xml.inp", + f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_zeroed.inp", fit_dihedral_atom_types, fit_dihedral_opls_k_0_1_2_3_4_values=[0, 0, 0, 0, 0], zeroed_dihedral_atom_types=zeroed_dihedral_atom_types, @@ -793,21 +831,32 @@ def fit_dihedral_with_gomc( os.mkdir(xyz_xsc_coor_files_directory) # write all the xyz coordinate from the Guassian optimized coordinate file in the 'xyz_files' folder - [atom_pdb_names_list, elementpdb_names_list] = mdf_frw.get_atom_names_and_elements_from_pdb( + [ + atom_pdb_names_list, + elementpdb_names_list, + ] = mdf_frw.get_atom_names_and_elements_from_pdb( f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}.pdb" ) - qm_energy_file_dir_and_name = 'extracted_guassian_data/dihedral.txt' - qm_parital_coordinate_file_starting_dir_and_name = 'extracted_guassian_data/dihedral_coords_position_' - qm_coordinate_file_extension = 'txt' + qm_energy_file_dir_and_name = "extracted_guassian_data/dihedral.txt" + qm_parital_coordinate_file_starting_dir_and_name = ( + "extracted_guassian_data/dihedral_coords_position_" + ) + qm_coordinate_file_extension = "txt" # check the gaussian file is correct mdf_frw.check_guassian_angle_energy_file_correct( - qm_energy_file_dir_and_name) + qm_energy_file_dir_and_name + ) # Read the gaussian data and extract angles and number of scans (number of angles and degress analyzed) - Guassian_raw_degrees_list = pd.DataFrame(pd.read_csv( - qm_energy_file_dir_and_name, sep='\s+', header=3)).iloc[:, 0].tolist() + Guassian_raw_degrees_list = ( + pd.DataFrame( + pd.read_csv(qm_energy_file_dir_and_name, sep="\s+", header=3) + ) + .iloc[:, 0] + .tolist() + ) total_qm_scans = len(Guassian_raw_degrees_list) mdf_frw.write_xyz_file_from_gaussian_coordinates( @@ -815,12 +864,13 @@ def fit_dihedral_with_gomc( qm_parital_coordinate_file_starting_dir_and_name, qm_coordinate_file_extension, xyz_xsc_coor_files_directory, - total_qm_scans + total_qm_scans, ) # Using vmd write the GOMC restart .coor files required for the mdf_frw.write_restart_coor_from_xyz_file( - xyz_xsc_coor_files_directory, total_qm_scans) + xyz_xsc_coor_files_directory, total_qm_scans + ) # ************************************************************** # Create the xyz files in a folder so VMD can read them with @@ -836,13 +886,15 @@ def fit_dihedral_with_gomc( # write the GOMC control files for scan_iter in range(1, len(Guassian_raw_degrees_list) + 1): + read_gomc_restart_file_coor_dir_and_name = f"../{xyz_xsc_coor_files_directory}/dihedral_coords_position_{scan_iter}.coor" + read_gomc_restart_file_xsc_dir_and_name = ( + f"../{xyz_xsc_coor_files_directory}/starting_point.xsc" + ) - read_gomc_restart_file_coor_dir_and_name = \ - f'../{xyz_xsc_coor_files_directory}/dihedral_coords_position_{scan_iter}.coor' - read_gomc_restart_file_xsc_dir_and_name = f'../{xyz_xsc_coor_files_directory}/starting_point.xsc' - - control_file_name_str = f'GOMC_zeroed_dihedral_coords_{scan_iter}.conf' - output_name_control_file_name_str = f'output_GOMC_zeroed_dihedral_coords_{scan_iter}.txt' + control_file_name_str = f"GOMC_zeroed_dihedral_coords_{scan_iter}.conf" + output_name_control_file_name_str = ( + f"output_GOMC_zeroed_dihedral_coords_{scan_iter}.txt" + ) # cutoff and tail correction Rcut = int(liquid_box_0_length_nm * 10 / 2) * u.angstrom @@ -860,7 +912,9 @@ def fit_dihedral_with_gomc( SwapFreq = 0 print("#**********************") - print("Started: NVT GOMC control file writing for the GOMC simulation with dihedral k values = 0") + print( + "Started: NVT GOMC control file writing for the GOMC simulation with dihedral k values = 0" + ) print("#**********************") # calc MC steps for gomc equilb MC_steps = 2 @@ -873,8 +927,8 @@ def fit_dihedral_with_gomc( gomc_control.write_gomc_control_file( charmm, - f'{gomc_runs_folder_name}/{control_file_name_str}', - 'NVT', + f"{gomc_runs_folder_name}/{control_file_name_str}", + "NVT", MC_steps, temperature_unyt_units, ff_psf_pdb_file_directory=None, @@ -929,7 +983,9 @@ def fit_dihedral_with_gomc( }, ) print("#**********************") - print("Completed: NVT GOMC control file written for the GOMC simulation with dihedral k values = 0") + print( + "Completed: NVT GOMC control file written for the GOMC simulation with dihedral k values = 0" + ) print("#**********************") # ************************************************************** @@ -940,22 +996,26 @@ def fit_dihedral_with_gomc( # Write the restart .xsc file for GOMC (START) # ********************************* gomc_restart_xsc_txt_file = open( - f'{xyz_xsc_coor_files_directory}/starting_point.xsc', "w") + f"{xyz_xsc_coor_files_directory}/starting_point.xsc", "w" + ) gomc_restart_xsc_txt_file.write( - f"# GOMC extended system configuration output file\n") + f"# GOMC extended system configuration output file\n" + ) gomc_restart_xsc_txt_file.write( f"#$LABELS step a_x a_y a_z b_x b_y b_z c_x c_y c_z o_x o_y o_z s_x s_y s_z s_u s_v s_w\n" ) - gomc_restart_xsc_txt_file.write(f"1 {Rcut.to_value('angstrom') * 2} 0 0 " - f"0 {Rcut.to_value('angstrom') * 2} 0 " - f"0 0 {Rcut.to_value('angstrom') * 2} " - f"{Rcut.to_value('angstrom')} " - f"{Rcut.to_value('angstrom')} " - f"{Rcut.to_value('angstrom')} " - f"0 0 0 " - f"0 0 0" - f"\n") + gomc_restart_xsc_txt_file.write( + f"1 {Rcut.to_value('angstrom') * 2} 0 0 " + f"0 {Rcut.to_value('angstrom') * 2} 0 " + f"0 0 {Rcut.to_value('angstrom') * 2} " + f"{Rcut.to_value('angstrom')} " + f"{Rcut.to_value('angstrom')} " + f"{Rcut.to_value('angstrom')} " + f"0 0 0 " + f"0 0 0" + f"\n" + ) gomc_restart_xsc_txt_file.close() # ********************************* # Write the restart .xsc file for GOMC (END) @@ -966,9 +1026,10 @@ def fit_dihedral_with_gomc( # ************************************************************** # only run NVT as we only want/need the initial energy and want the box a constant size - run_gomc_command = \ - f"cd {gomc_runs_folder_name} && {gomc_binary_path}/GOMC_CPU_NVT +p{gomc_cpu_cores} " \ + run_gomc_command = ( + f"cd {gomc_runs_folder_name} && {gomc_binary_path}/GOMC_CPU_NVT +p{gomc_cpu_cores} " f"{control_file_name_str} > {output_name_control_file_name_str}" + ) exec_gomc_run_command = subprocess.Popen( run_gomc_command, shell=True, stderr=subprocess.STDOUT @@ -984,35 +1045,46 @@ def fit_dihedral_with_gomc( # open the gomc raw energy file so it can be writen over in the loop read_gomc_log_file = open( - f'{gomc_runs_folder_name}/{output_name_control_file_name_str}', "r").readlines() + f"{gomc_runs_folder_name}/{output_name_control_file_name_str}", "r" + ).readlines() get_e_titles = True for log_file_iter, log_file_line_iter in enumerate(read_gomc_log_file): log_file_splitline_iter = log_file_line_iter.split() # scan_iter starts at 1 - dihedral_angle_degrees = Guassian_raw_degrees_list[scan_iter-1] + dihedral_angle_degrees = Guassian_raw_degrees_list[scan_iter - 1] # only open the gomc raw energy file and write header for 1st iteration (1) if len(log_file_splitline_iter) >= 2: - if scan_iter == 1 and log_file_splitline_iter[0] == "ETITLE:" and get_e_titles is True: + if ( + scan_iter == 1 + and log_file_splitline_iter[0] == "ETITLE:" + and get_e_titles is True + ): gomc_combined_raw_energy = open( - gomc_raw_energy_filename, "w") + gomc_raw_energy_filename, "w" + ) # remove the wrongly entered 5 spaces in before "ETITLE: # (This will be fixed in GOMC so it is not required) extra_spaces_for_header_space_gomc_bug = 5 - gomc_combined_raw_energy.write(f'{"Dihedral_Position": <19} ' - f'{"Dihedral_Degrees": <19} ' - f'{log_file_line_iter[extra_spaces_for_header_space_gomc_bug:]}' - ) + gomc_combined_raw_energy.write( + f'{"Dihedral_Position": <19} ' + f'{"Dihedral_Degrees": <19} ' + f"{log_file_line_iter[extra_spaces_for_header_space_gomc_bug:]}" + ) if get_e_titles is True: get_e_titles = False # get only the initial configuration energy lin (i.e., step 0 line) - if log_file_splitline_iter[0] == 'ENER_0:' and log_file_splitline_iter[1] == '0': - gomc_combined_raw_energy.write(f'{scan_iter: <19}' - f'{dihedral_angle_degrees: <19} ' - f'{log_file_line_iter[5:]}' - ) + if ( + log_file_splitline_iter[0] == "ENER_0:" + and log_file_splitline_iter[1] == "0" + ): + gomc_combined_raw_energy.write( + f"{scan_iter: <19}" + f"{dihedral_angle_degrees: <19} " + f"{log_file_line_iter[5:]}" + ) # This fails when the GOMC simulations did not run try: @@ -1020,8 +1092,10 @@ def fit_dihedral_with_gomc( gomc_combined_raw_energy.close() except: - raise ValueError("ERROR: The GOMC simulations did not run. There is likely an error in creating the " - "required GOMC files or user inputs to the desired files.") + raise ValueError( + "ERROR: The GOMC simulations did not run. There is likely an error in creating the " + "required GOMC files or user inputs to the desired files." + ) # ************************************************************** # ************************************************************** @@ -1035,32 +1109,40 @@ def fit_dihedral_with_gomc( # ************************************************************** conversion_hartree_to_kcal_per_mol = 627.509474063 - conversion_K_to_kcal_per_mol = ( - 1 * u.Kelvin).to_value("kcal/mol", equivalence="thermal") + conversion_K_to_kcal_per_mol = (1 * u.Kelvin).to_value( + "kcal/mol", equivalence="thermal" + ) # ********************************* # get GOMC data (START) # ********************************* # extract the raw data - GOMC_data_df = pd.DataFrame(pd.read_csv( - gomc_raw_energy_filename, sep='\s+')) - GOMC_data_dihedral_degrees_list = GOMC_data_df.loc[:, 'Dihedral_Degrees'].tolist( + GOMC_data_df = pd.DataFrame( + pd.read_csv(gomc_raw_energy_filename, sep="\s+") ) - GOMC_data_total_energy_K_list = GOMC_data_df.loc[:, 'TOTAL'].tolist() + GOMC_data_dihedral_degrees_list = GOMC_data_df.loc[ + :, "Dihedral_Degrees" + ].tolist() + GOMC_data_total_energy_K_list = GOMC_data_df.loc[:, "TOTAL"].tolist() # convert from Kelvin to kcal/mol normalize so the min value is 0 - GOMC_data_total_energy_kcal_per_mol_list = \ - [i * conversion_K_to_kcal_per_mol for i in GOMC_data_total_energy_K_list] - GOMC_data_total_energy_kcal_per_mol_normalize_list = \ - [i - min(GOMC_data_total_energy_kcal_per_mol_list) - for i in GOMC_data_total_energy_kcal_per_mol_list] + GOMC_data_total_energy_kcal_per_mol_list = [ + i * conversion_K_to_kcal_per_mol for i in GOMC_data_total_energy_K_list + ] + GOMC_data_total_energy_kcal_per_mol_normalize_list = [ + i - min(GOMC_data_total_energy_kcal_per_mol_list) + for i in GOMC_data_total_energy_kcal_per_mol_list + ] print( - f"GOMC_data_dihedral_degrees_list = {GOMC_data_dihedral_degrees_list}") + f"GOMC_data_dihedral_degrees_list = {GOMC_data_dihedral_degrees_list}" + ) print( - f"GOMC_data_total_energy_kcal_per_mol_list = {GOMC_data_total_energy_kcal_per_mol_list}") + f"GOMC_data_total_energy_kcal_per_mol_list = {GOMC_data_total_energy_kcal_per_mol_list}" + ) print( - f"GOMC_data_total_energy_kcal_per_mol_normalize_list = {GOMC_data_total_energy_kcal_per_mol_normalize_list}") + f"GOMC_data_total_energy_kcal_per_mol_normalize_list = {GOMC_data_total_energy_kcal_per_mol_normalize_list}" + ) # ********************************* # get GOMC data (END) # ********************************* @@ -1070,48 +1152,63 @@ def fit_dihedral_with_gomc( # ********************************* # extract the raw data - Guassian_data_df = pd.DataFrame(pd.read_csv( - qm_energy_file_dir_and_name, sep='\s+', header=3)) - Guassian_data_dihedral_degrees_list = Guassian_data_df.iloc[:, 0].tolist() - Guassian_data_total_energy_Hartree_list = Guassian_data_df.iloc[:, 1].tolist( + Guassian_data_df = pd.DataFrame( + pd.read_csv(qm_energy_file_dir_and_name, sep="\s+", header=3) ) + Guassian_data_dihedral_degrees_list = Guassian_data_df.iloc[:, 0].tolist() + Guassian_data_total_energy_Hartree_list = Guassian_data_df.iloc[ + :, 1 + ].tolist() # convert from Hartree to kcal/mol energy units - Guassian_data_total_energy_kcal_per_mol_list = \ - [i * conversion_hartree_to_kcal_per_mol for i in Guassian_data_total_energy_Hartree_list] + Guassian_data_total_energy_kcal_per_mol_list = [ + i * conversion_hartree_to_kcal_per_mol + for i in Guassian_data_total_energy_Hartree_list + ] # normalize so the min value is 0 - Guassian_data_total_energy_kcal_per_mol_normalize_list = \ - [i - min(Guassian_data_total_energy_kcal_per_mol_list) - for i in Guassian_data_total_energy_kcal_per_mol_list] + Guassian_data_total_energy_kcal_per_mol_normalize_list = [ + i - min(Guassian_data_total_energy_kcal_per_mol_list) + for i in Guassian_data_total_energy_kcal_per_mol_list + ] print( - f"Guassian_data_dihedral_degrees_list = {Guassian_data_dihedral_degrees_list}") + f"Guassian_data_dihedral_degrees_list = {Guassian_data_dihedral_degrees_list}" + ) print( - f"Guassian_data_total_energy_kcal_per_mol_list = {Guassian_data_total_energy_kcal_per_mol_list}") - print(f"Guassian_data_total_energy_kcal_per_mol_normalize_list = " - f"{Guassian_data_total_energy_kcal_per_mol_normalize_list}" - ) + f"Guassian_data_total_energy_kcal_per_mol_list = {Guassian_data_total_energy_kcal_per_mol_list}" + ) + print( + f"Guassian_data_total_energy_kcal_per_mol_normalize_list = " + f"{Guassian_data_total_energy_kcal_per_mol_normalize_list}" + ) # get the Gaussian minus GOMC total energy and then it normalized - Gaussian_minus_GOMC_data_dihedral_degrees_list = GOMC_data_dihedral_degrees_list + Gaussian_minus_GOMC_data_dihedral_degrees_list = ( + GOMC_data_dihedral_degrees_list + ) Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list = [ Guassian_data_total_energy_kcal_per_mol_normalize_list[i] - GOMC_data_total_energy_kcal_per_mol_normalize_list[i] - for i in range(0, len(Guassian_data_total_energy_kcal_per_mol_normalize_list)) + for i in range( + 0, len(Guassian_data_total_energy_kcal_per_mol_normalize_list) + ) ] Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list = [ - Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list[i] - - min(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list) - for i in range(0, len(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list)) + Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list[i] + - min(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list) + for i in range( + 0, len(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list) + ) ] print( - f'Gaussian_minus_GOMC_data_dihedral_degrees_list = {Gaussian_minus_GOMC_data_dihedral_degrees_list}') + f"Gaussian_minus_GOMC_data_dihedral_degrees_list = {Gaussian_minus_GOMC_data_dihedral_degrees_list}" + ) print( - f'Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list = \ - {Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list}' + f"Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list = \ + {Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list}" ) # ********************************* # get Gaussian data (END) @@ -1129,7 +1226,7 @@ def fit_dihedral_with_gomc( matching_dihedral_types_by_atom_type_list, all_matching_dihedral_coordinates_angstroms_added_to_k_values_list, all_matching_dihedral_phi_degrees_added_to_k_values_list, - all_sum_opls_const_1_plus_or_minus_cos_n_list + all_sum_opls_const_1_plus_or_minus_cos_n_list, ] = mdf_frw.get_matching_dihedral_info_and_opls_fitting_data( fit_dihedral_atom_types, f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}.psf", @@ -1144,7 +1241,7 @@ def fit_dihedral_with_gomc( matching_dihedral_types_by_atom_type_list, all_matching_dihedral_coordinates_angstroms_added_to_k_values_list, all_matching_dihedral_phi_degrees_added_to_k_values_list, - all_sum_opls_const_1_plus_or_minus_cos_n_list + all_sum_opls_const_1_plus_or_minus_cos_n_list, ] = mdf_frw.get_matching_dihedral_info_and_opls_fitting_data( fit_dihedral_atom_types, f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}.psf", @@ -1164,17 +1261,20 @@ def fit_dihedral_with_gomc( const_1_minus_Cos_2_phi_data_lists = [] const_1_plus_Cos_3_phi_data_lists = [] const_1_minus_Cos_4_phi_data_lists = [] - for const_1_plus_or_minus_cos_i in all_sum_opls_const_1_plus_or_minus_cos_n_list: + for ( + const_1_plus_or_minus_cos_i + ) in all_sum_opls_const_1_plus_or_minus_cos_n_list: const_1_minus_Cos_0_phi_data_lists.append( - const_1_plus_or_minus_cos_i[0]) - const_1_plus_Cos_1_phi_data_lists.append( - const_1_plus_or_minus_cos_i[1]) + const_1_plus_or_minus_cos_i[0] + ) + const_1_plus_Cos_1_phi_data_lists.append(const_1_plus_or_minus_cos_i[1]) const_1_minus_Cos_2_phi_data_lists.append( - const_1_plus_or_minus_cos_i[2]) - const_1_plus_Cos_3_phi_data_lists.append( - const_1_plus_or_minus_cos_i[3]) + const_1_plus_or_minus_cos_i[2] + ) + const_1_plus_Cos_3_phi_data_lists.append(const_1_plus_or_minus_cos_i[3]) const_1_minus_Cos_4_phi_data_lists.append( - const_1_plus_or_minus_cos_i[4]) + const_1_plus_or_minus_cos_i[4] + ) # ********************************* # get all other dihedral angles (phi) that match the atom type of the scanned dihedral, @@ -1183,16 +1283,20 @@ def fit_dihedral_with_gomc( # ********************************* # Check if all the columns are the same length for GOMC and Gaussian data - if not len(GOMC_data_dihedral_degrees_list) \ - == len(GOMC_data_total_energy_kcal_per_mol_list) \ - == len(GOMC_data_total_energy_kcal_per_mol_normalize_list) \ - == len(Guassian_data_dihedral_degrees_list) \ - == len(Guassian_data_total_energy_kcal_per_mol_list) \ - == len(Guassian_data_total_energy_kcal_per_mol_normalize_list) \ - == len(Gaussian_minus_GOMC_data_dihedral_degrees_list) \ - == len(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list) \ - == len(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) \ - == len(all_sum_opls_const_1_plus_or_minus_cos_n_list): + if ( + not len(GOMC_data_dihedral_degrees_list) + == len(GOMC_data_total_energy_kcal_per_mol_list) + == len(GOMC_data_total_energy_kcal_per_mol_normalize_list) + == len(Guassian_data_dihedral_degrees_list) + == len(Guassian_data_total_energy_kcal_per_mol_list) + == len(Guassian_data_total_energy_kcal_per_mol_normalize_list) + == len(Gaussian_minus_GOMC_data_dihedral_degrees_list) + == len(Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_list) + == len( + Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ) + == len(all_sum_opls_const_1_plus_or_minus_cos_n_list) + ): raise ValueError( "ERROR: The GOMC and Guassian outputs do not match in length. " "This could mean something is changed and wrong in the code, " @@ -1202,19 +1306,26 @@ def fit_dihedral_with_gomc( # Check if all the angles match between sorted GOMC and Gaussian data for j_angle in range(0, len(GOMC_data_dihedral_degrees_list)): - if not len(GOMC_data_dihedral_degrees_list) == len(Guassian_data_dihedral_degrees_list): + if not len(GOMC_data_dihedral_degrees_list) == len( + Guassian_data_dihedral_degrees_list + ): raise ValueError( - "ERROR: The GOMC and Guassian output angles are not in the same angles in order.") + "ERROR: The GOMC and Guassian output angles are not in the same angles in order." + ) # Check if all the angles match between sorted GOMC and Gaussian data for k_angle in range(0, len(GOMC_data_dihedral_degrees_list)): - if not len(GOMC_data_dihedral_degrees_list) == len(Guassian_data_dihedral_degrees_list): + if not len(GOMC_data_dihedral_degrees_list) == len( + Guassian_data_dihedral_degrees_list + ): raise ValueError( - "ERROR: The GOMC and Guassian output angles are not in the same angles in order.") + "ERROR: The GOMC and Guassian output angles are not in the same angles in order." + ) if k_angle == 0: # write out the GOMC and Gaussian data in a file gomc_gaussian_kcal_mol_energy_data_txt_file = open( - gomc_gaussian_kcal_mol_energy_filename, "w") + gomc_gaussian_kcal_mol_energy_filename, "w" + ) gomc_gaussian_kcal_mol_energy_data_txt_file.write( f"{'Dihedral_Degrees': <30} " f"{'GOMC_E_kcal_per_mol': <30} " @@ -1264,23 +1375,25 @@ def fit_dihedral_with_gomc( fig1, (ax1) = plt.subplots(1) axis_Label_font_size = 12 legend_font_size = 12 - ax1.set_xlabel('phi (degrees)', size=axis_Label_font_size) - ax1.set_ylabel('Dihedral Energy (kcal/mol)', size=axis_Label_font_size) + ax1.set_xlabel("phi (degrees)", size=axis_Label_font_size) + ax1.set_ylabel("Dihedral Energy (kcal/mol)", size=axis_Label_font_size) # sort the by Dihedral_Degrees at the same time for # Dihedral_Degrees, GOMC_E_kcal_per_mol, Gaussian_E_kcal_per_mol, and Gaussian_minus_GOMC_E_kcal_per_mol - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list, \ - sorted_GOMC_data_total_energy_kcal_per_mol_normalize_list, \ - sorted_Guassian_data_total_energy_kcal_per_mol_normalize_list, \ - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list, \ - sorted_all_sum_opls_const_1_plus_or_minus_cos_n_list, \ - sorted_const_1_minus_Cos_0_phi_data_lists, \ - sorted_const_1_plus_Cos_1_phi_data_lists, \ - sorted_const_1_minus_Cos_2_phi_data_lists, \ - sorted_const_1_plus_Cos_3_phi_data_lists, \ - sorted_const_1_minus_Cos_4_phi_data_lists, \ - = zip( - *sorted(zip( + ( + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list, + sorted_GOMC_data_total_energy_kcal_per_mol_normalize_list, + sorted_Guassian_data_total_energy_kcal_per_mol_normalize_list, + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list, + sorted_all_sum_opls_const_1_plus_or_minus_cos_n_list, + sorted_const_1_minus_Cos_0_phi_data_lists, + sorted_const_1_plus_Cos_1_phi_data_lists, + sorted_const_1_minus_Cos_2_phi_data_lists, + sorted_const_1_plus_Cos_3_phi_data_lists, + sorted_const_1_minus_Cos_4_phi_data_lists, + ) = zip( + *sorted( + zip( Gaussian_minus_GOMC_data_dihedral_degrees_list, GOMC_data_total_energy_kcal_per_mol_normalize_list, Guassian_data_total_energy_kcal_per_mol_normalize_list, @@ -1290,16 +1403,27 @@ def fit_dihedral_with_gomc( const_1_plus_Cos_1_phi_data_lists, const_1_minus_Cos_2_phi_data_lists, const_1_plus_Cos_3_phi_data_lists, - const_1_minus_Cos_4_phi_data_lists - )) + const_1_minus_Cos_4_phi_data_lists, + ) ) + ) - print(f"sorted_GOMC_data_total_energy_kcal_per_mol_normalize_list = {sorted_GOMC_data_total_energy_kcal_per_mol_normalize_list}") - print(f"sorted_Guassian_data_total_energy_kcal_per_mol_normalize_list = {sorted_Guassian_data_total_energy_kcal_per_mol_normalize_list}") - print(f"sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list = {sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list}") + print( + f"sorted_GOMC_data_total_energy_kcal_per_mol_normalize_list = {sorted_GOMC_data_total_energy_kcal_per_mol_normalize_list}" + ) + print( + f"sorted_Guassian_data_total_energy_kcal_per_mol_normalize_list = {sorted_Guassian_data_total_energy_kcal_per_mol_normalize_list}" + ) + print( + f"sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list = {sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list}" + ) - plot_max = int(max( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + 1.51) + plot_max = int( + max( + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ) + + 1.51 + ) ax1.set_ylim(-int(plot_max * 1.5), plot_max) plt.title( "OPLS: All viable summed dihedral fits $\Longrightarrow$ $\Sigma$ matching dihedrals. \n" @@ -1309,16 +1433,20 @@ def fit_dihedral_with_gomc( # loop thru dihderal_k_zeros_list_k0_k1_k2_k3_k4 list and fit all that are listed in here # add add the label designnator k's used (i.e., Non-zero k's = 1 and 3 -> label '1_3') # and write the constants out - end_part_dihedral_k_constants_fit_energy_figure_filename = \ + end_part_dihedral_k_constants_fit_energy_figure_filename = ( "all_summed_dihedrals_k_constants_figure.pdf" + ) - all_individual_fit_dihedral_k_constants_figure_filename = \ + all_individual_fit_dihedral_k_constants_figure_filename = ( "all_single_fit_dihedral_k_constants_figure.pdf" + ) - end_part_dihedral_k_constants_fit_energy_filename = \ + end_part_dihedral_k_constants_fit_energy_filename = ( "k_constants_fit_energy.txt" + ) opls_dihedral_k_constants_fit_energy_kcal_mol_txt_file = open( - f"{'opls_dihedral'}_{end_part_dihedral_k_constants_fit_energy_filename}", "w" + f"{'opls_dihedral'}_{end_part_dihedral_k_constants_fit_energy_filename}", + "w", ) opls_dihedral_k_constants_fit_energy_kcal_mol_txt_file.write( f"{'non_zero_k_constants': <25} " @@ -1340,16 +1468,16 @@ def fit_dihedral_with_gomc( # (i.e, n = 1 and 3 --> "1_3", i.e, n = 1 2, and 3 --> "1_2_3")) # fit_k_list = [ - '1', - '2', - '3', - '4', - '1_3', - '2_4', - '3_4', - '1_2', - '1_2_3', - '1_2_3_4', + "1", + "2", + "3", + "4", + "1_3", + "2_4", + "3_4", + "1_2", + "1_2_3", + "1_2_3_4", ] # Determine which power values you can use. @@ -1366,76 +1494,113 @@ def fit_dihedral_with_gomc( # can be used in the fitting. If there is only 1 that is different in a large # group, it may not be wrong, if it is not minimized in QM.... number_of_differnt_const_cos_needed_int = int( - 25 / 100 * len(sorted_const_1_plus_Cos_1_phi_data_lists) + 1) + 25 / 100 * len(sorted_const_1_plus_Cos_1_phi_data_lists) + 1 + ) for ck_const_i in range(0, len(sorted_const_1_plus_Cos_1_phi_data_lists)): # Check if can use cos power 1 - if bool( + if ( + bool( np.isclose( mdf_math.round_to_sig_figs( - sorted_const_1_plus_Cos_1_phi_data_lists[ck_const_i], sig_figs=check_sig_figs + sorted_const_1_plus_Cos_1_phi_data_lists[ck_const_i], + sig_figs=check_sig_figs, ), mdf_math.round_to_sig_figs( - sorted_const_1_plus_Cos_1_phi_data_lists[0], sig_figs=check_sig_figs - ) + sorted_const_1_plus_Cos_1_phi_data_lists[0], + sig_figs=check_sig_figs, + ), ) - ) is False: - const_cos_count_powers_1_2_3_and_4_int_list[0] = 1 + \ - const_cos_count_powers_1_2_3_and_4_int_list[0] + ) + is False + ): + const_cos_count_powers_1_2_3_and_4_int_list[0] = ( + 1 + const_cos_count_powers_1_2_3_and_4_int_list[0] + ) # Check if can use cos power 2 - if bool( + if ( + bool( np.isclose( mdf_math.round_to_sig_figs( - sorted_const_1_minus_Cos_2_phi_data_lists[ck_const_i], sig_figs=check_sig_figs + sorted_const_1_minus_Cos_2_phi_data_lists[ck_const_i], + sig_figs=check_sig_figs, ), mdf_math.round_to_sig_figs( - sorted_const_1_minus_Cos_2_phi_data_lists[0], sig_figs=check_sig_figs - ) + sorted_const_1_minus_Cos_2_phi_data_lists[0], + sig_figs=check_sig_figs, + ), ) - ) is False: - const_cos_count_powers_1_2_3_and_4_int_list[1] = 1 + \ - const_cos_count_powers_1_2_3_and_4_int_list[1] + ) + is False + ): + const_cos_count_powers_1_2_3_and_4_int_list[1] = ( + 1 + const_cos_count_powers_1_2_3_and_4_int_list[1] + ) # Check if can use cos power 3 - if bool( + if ( + bool( np.isclose( mdf_math.round_to_sig_figs( - sorted_const_1_plus_Cos_3_phi_data_lists[ck_const_i], sig_figs=check_sig_figs + sorted_const_1_plus_Cos_3_phi_data_lists[ck_const_i], + sig_figs=check_sig_figs, ), mdf_math.round_to_sig_figs( - sorted_const_1_plus_Cos_3_phi_data_lists[0], sig_figs=check_sig_figs - ) + sorted_const_1_plus_Cos_3_phi_data_lists[0], + sig_figs=check_sig_figs, + ), ) - ) is False: - const_cos_count_powers_1_2_3_and_4_int_list[2] = 1 + \ - const_cos_count_powers_1_2_3_and_4_int_list[2] + ) + is False + ): + const_cos_count_powers_1_2_3_and_4_int_list[2] = ( + 1 + const_cos_count_powers_1_2_3_and_4_int_list[2] + ) # Check if can use cos power 4 - if bool( + if ( + bool( np.isclose( mdf_math.round_to_sig_figs( - sorted_const_1_minus_Cos_4_phi_data_lists[ck_const_i], sig_figs=check_sig_figs + sorted_const_1_minus_Cos_4_phi_data_lists[ck_const_i], + sig_figs=check_sig_figs, ), mdf_math.round_to_sig_figs( - sorted_const_1_minus_Cos_4_phi_data_lists[0], sig_figs=check_sig_figs - ) + sorted_const_1_minus_Cos_4_phi_data_lists[0], + sig_figs=check_sig_figs, + ), ) - ) is False: - const_cos_count_powers_1_2_3_and_4_int_list[3] = 1 + \ - const_cos_count_powers_1_2_3_and_4_int_list[3] + ) + is False + ): + const_cos_count_powers_1_2_3_and_4_int_list[3] = ( + 1 + const_cos_count_powers_1_2_3_and_4_int_list[3] + ) # add the cos power value if enough differences in the constants are seen - if const_cos_count_powers_1_2_3_and_4_int_list[0] >= number_of_differnt_const_cos_needed_int: - allowed_fitting_powers_1_2_3_and_4.append('1') + if ( + const_cos_count_powers_1_2_3_and_4_int_list[0] + >= number_of_differnt_const_cos_needed_int + ): + allowed_fitting_powers_1_2_3_and_4.append("1") - if const_cos_count_powers_1_2_3_and_4_int_list[1] >= number_of_differnt_const_cos_needed_int: - allowed_fitting_powers_1_2_3_and_4.append('2') + if ( + const_cos_count_powers_1_2_3_and_4_int_list[1] + >= number_of_differnt_const_cos_needed_int + ): + allowed_fitting_powers_1_2_3_and_4.append("2") - if const_cos_count_powers_1_2_3_and_4_int_list[2] >= number_of_differnt_const_cos_needed_int: - allowed_fitting_powers_1_2_3_and_4.append('3') + if ( + const_cos_count_powers_1_2_3_and_4_int_list[2] + >= number_of_differnt_const_cos_needed_int + ): + allowed_fitting_powers_1_2_3_and_4.append("3") - if const_cos_count_powers_1_2_3_and_4_int_list[3] >= number_of_differnt_const_cos_needed_int: - allowed_fitting_powers_1_2_3_and_4.append('4') + if ( + const_cos_count_powers_1_2_3_and_4_int_list[3] + >= number_of_differnt_const_cos_needed_int + ): + allowed_fitting_powers_1_2_3_and_4.append("4") allowed_fitting_powers_1_2_3_and_4.sort() @@ -1447,8 +1612,10 @@ def fit_dihedral_with_gomc( for mod_i, mod_val in enumerate(fit_k_list): power_allowed_iter = True for str_i in mod_val: - - if str_i not in ['-', '_'] and str_i not in allowed_fitting_powers_1_2_3_and_4: + if ( + str_i not in ["-", "_"] + and str_i not in allowed_fitting_powers_1_2_3_and_4 + ): power_allowed_iter = False if power_allowed_iter is True: fit_k_list_allowed.append(mod_val) @@ -1463,25 +1630,28 @@ def fit_dihedral_with_gomc( for k_iter_i, k_type_i in enumerate(fit_k_list_allowed): # make the list of k_type_i for fitting in the data k_type_list_i = [] - for v in range(0, len(sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list)): + for v in range( + 0, len(sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list) + ): k_type_list_i.append(k_type_i) - if k_type_i == '1': - + if k_type_i == "1": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, @@ -1496,12 +1666,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1510,21 +1681,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '2': + elif k_type_i == "2": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1538,12 +1711,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1552,21 +1726,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '3': + elif k_type_i == "3": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1580,12 +1756,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1594,21 +1771,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '4': + elif k_type_i == "4": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1622,12 +1801,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1636,21 +1816,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '1_3': + elif k_type_i == "1_3": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1663,12 +1845,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1677,21 +1860,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '2_4': + elif k_type_i == "2_4": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1704,12 +1889,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1718,21 +1904,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '1_2': + elif k_type_i == "1_2": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1745,12 +1933,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1759,21 +1948,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '3_4': + elif k_type_i == "3_4": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1786,12 +1977,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1800,21 +1992,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '1_2_3': + elif k_type_i == "1_2_3": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1826,12 +2020,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1840,21 +2035,23 @@ def fit_dihedral_with_gomc( parameters[4], ) - elif k_type_i == '1_2_3_4': + elif k_type_i == "1_2_3_4": parameters, covariance = curve_fit( mdf_math.opls_dihedral, ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), np.asarray( - sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list) + sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list + ), ) # fix parameters to zero for the unused values because we want the list length the same, # and the unused ones are auto-set to 1. @@ -1865,12 +2062,13 @@ def fit_dihedral_with_gomc( ( np.asarray(k_type_list_i), np.asarray( - sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list + ), np.asarray(sorted_const_1_minus_Cos_0_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_1_phi_data_lists), np.asarray(sorted_const_1_minus_Cos_2_phi_data_lists), np.asarray(sorted_const_1_plus_Cos_3_phi_data_lists), - np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists) + np.asarray(sorted_const_1_minus_Cos_4_phi_data_lists), ), parameters[0], parameters[1], @@ -1881,18 +2079,20 @@ def fit_dihedral_with_gomc( else: raise ValueError( - f"ERROR: The {k_type_i} selected in the 'fit_k_list' variable is not a valid selection") + f"ERROR: The {k_type_i} selected in the 'fit_k_list' variable is not a valid selection" + ) # calulate TSS, RSS and R**2 r_squared = mdf_math.get_r_squared( sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list, - fit_opls_dihedral + fit_opls_dihedral, ) plt.plot( - np.asarray(sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), np.asarray( - fit_opls_dihedral), - '-', label=f" {k_type_i} | $R^{2}$={np.round(r_squared, decimals=4)}" + np.asarray(sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list), + np.asarray(fit_opls_dihedral), + "-", + label=f" {k_type_i} | $R^{2}$={np.round(r_squared, decimals=4)}", ) # wrie out the k constants and R^2 @@ -1910,7 +2110,8 @@ def fit_dihedral_with_gomc( plt.plot( sorted_Gaussian_minus_GOMC_data_dihedral_degrees_list, sorted_Gaussian_minus_GOMC_data_total_energy_kcal_per_mol_normalized_list, - 'o', label='Data' + "o", + label="Data", ) # close the file @@ -1926,12 +2127,14 @@ def fit_dihedral_with_gomc( ncol=2, loc="lower center", fontsize=legend_font_size, - prop={'family': 'Arial', 'size': legend_font_size} + prop={"family": "Arial", "size": legend_font_size}, ) # plt.show() fig1.savefig( - f"opls_{end_part_dihedral_k_constants_fit_energy_figure_filename}", dpi=300) + f"opls_{end_part_dihedral_k_constants_fit_energy_figure_filename}", + dpi=300, + ) # ********************************* # fit the Gaussian - GOMC dihedral (END) @@ -1941,25 +2144,31 @@ def fit_dihedral_with_gomc( # Plot all OPLS dihedral to fitted forms together (START) # ********************************* opls_fit_data_df = pd.DataFrame( - pd.read_csv(f"{'opls_dihedral'}_{end_part_dihedral_k_constants_fit_energy_filename}", - sep='\s+', - header=0 - ) - ) - opls_fit_data_non_zero_k_constants_list = opls_fit_data_df.loc[:, 'non_zero_k_constants'].tolist( - ) - opls_fit_data_k0_kcal_per_mol_list = opls_fit_data_df.loc[:, 'k0_kcal_per_mol'].tolist( - ) - opls_fit_data_k1_kcal_per_mol_list = opls_fit_data_df.loc[:, 'k1_kcal_per_mol'].tolist( - ) - opls_fit_data_k2_kcal_per_mol_list = opls_fit_data_df.loc[:, 'k2_kcal_per_mol'].tolist( - ) - opls_fit_data_k3_kcal_per_mol_list = opls_fit_data_df.loc[:, 'k3_kcal_per_mol'].tolist( - ) - opls_fit_data_k4_kcal_per_mol_list = opls_fit_data_df.loc[:, 'k4_kcal_per_mol'].tolist( - ) - opls_fit_data_r_squared_list = opls_fit_data_df.loc[:, 'r_squared'].tolist( + pd.read_csv( + f"{'opls_dihedral'}_{end_part_dihedral_k_constants_fit_energy_filename}", + sep="\s+", + header=0, + ) ) + opls_fit_data_non_zero_k_constants_list = opls_fit_data_df.loc[ + :, "non_zero_k_constants" + ].tolist() + opls_fit_data_k0_kcal_per_mol_list = opls_fit_data_df.loc[ + :, "k0_kcal_per_mol" + ].tolist() + opls_fit_data_k1_kcal_per_mol_list = opls_fit_data_df.loc[ + :, "k1_kcal_per_mol" + ].tolist() + opls_fit_data_k2_kcal_per_mol_list = opls_fit_data_df.loc[ + :, "k2_kcal_per_mol" + ].tolist() + opls_fit_data_k3_kcal_per_mol_list = opls_fit_data_df.loc[ + :, "k3_kcal_per_mol" + ].tolist() + opls_fit_data_k4_kcal_per_mol_list = opls_fit_data_df.loc[ + :, "k4_kcal_per_mol" + ].tolist() + opls_fit_data_r_squared_list = opls_fit_data_df.loc[:, "r_squared"].tolist() # ********************************* # Plot all OPLS dihedral to fitted forms together (END) @@ -1971,7 +2180,8 @@ def fit_dihedral_with_gomc( # create the Periodic / CHARMM dihedrals file periodic_dihedral_k_constants_fit_energy_kcal_mol_txt_file = open( - f"{'periodic_dihedral'}_{end_part_dihedral_k_constants_fit_energy_filename}", "w" + f"{'periodic_dihedral'}_{end_part_dihedral_k_constants_fit_energy_filename}", + "w", ) periodic_dihedral_k_constants_fit_energy_kcal_mol_txt_file.write( f"{'non_zero_k_constants': <25} " @@ -1998,7 +2208,8 @@ def fit_dihedral_with_gomc( # create the RB torsions file RB_torsion_k_constants_fit_energy_kcal_mol_txt_file = open( - f"{'RB_torsion'}_{end_part_dihedral_k_constants_fit_energy_filename}", "w" + f"{'RB_torsion'}_{end_part_dihedral_k_constants_fit_energy_filename}", + "w", ) RB_torsion_k_constants_fit_energy_kcal_mol_txt_file.write( f"{'non_zero_k_constants': <25} " @@ -2016,9 +2227,10 @@ def fit_dihedral_with_gomc( # list the phi values to check phi_check_degrees = 1 phi_check_number_of_degree_values = int(360 / phi_check_degrees) - phi_values_for_check_degrees_list = \ - [-180 + i * - phi_check_degrees for i in range(0, phi_check_number_of_degree_values)] + phi_values_for_check_degrees_list = [ + -180 + i * phi_check_degrees + for i in range(0, phi_check_number_of_degree_values) + ] cos_power_list = [ opls_fit_data_non_zero_k_constants_list[opls_fit_i] @@ -2026,7 +2238,9 @@ def fit_dihedral_with_gomc( ] # check if the periodic and opls dihedral energies match all the values in the list - for period_opls_ck_i in range(0, len(phi_values_for_check_degrees_list)): + for period_opls_ck_i in range( + 0, len(phi_values_for_check_degrees_list) + ): # calculate the dihedral energy for a check to the converted dihedrals opls_dihedral_energy_check = mdf_math.opls_dihedral( ( @@ -2036,13 +2250,13 @@ def fit_dihedral_with_gomc( None, None, None, - None + None, ), opls_fit_data_k0_kcal_per_mol_list[opls_fit_i], opls_fit_data_k1_kcal_per_mol_list[opls_fit_i], opls_fit_data_k2_kcal_per_mol_list[opls_fit_i], opls_fit_data_k3_kcal_per_mol_list[opls_fit_i], - opls_fit_data_k4_kcal_per_mol_list[opls_fit_i] + opls_fit_data_k4_kcal_per_mol_list[opls_fit_i], ) # check if the periodic and opls dihedral energies match all the values in the list @@ -2057,33 +2271,37 @@ def fit_dihedral_with_gomc( opls_fit_data_k1_kcal_per_mol_list[opls_fit_i], opls_fit_data_k2_kcal_per_mol_list[opls_fit_i], opls_fit_data_k3_kcal_per_mol_list[opls_fit_i], - opls_fit_data_k4_kcal_per_mol_list[opls_fit_i] + opls_fit_data_k4_kcal_per_mol_list[opls_fit_i], ) - periodic_dihedral_energy_check = mdf_math.periodic_dihedral_n_1_2_3_4_5( - phi_values_for_check_degrees_list[opls_fit_i], - periodic_dihedral_k_n_d_values[0][0], - periodic_dihedral_k_n_d_values[1][0], - periodic_dihedral_k_n_d_values[2][0], - periodic_dihedral_k_n_d_values[3][0], - periodic_dihedral_k_n_d_values[4][0], - periodic_dihedral_k_n_d_values[5][0], - periodic_dihedral_k_n_d_values[0][1], - periodic_dihedral_k_n_d_values[1][1], - periodic_dihedral_k_n_d_values[2][1], - periodic_dihedral_k_n_d_values[3][1], - periodic_dihedral_k_n_d_values[4][1], - periodic_dihedral_k_n_d_values[5][1], - periodic_dihedral_k_n_d_values[0][2], - periodic_dihedral_k_n_d_values[1][2], - periodic_dihedral_k_n_d_values[2][2], - periodic_dihedral_k_n_d_values[3][2], - periodic_dihedral_k_n_d_values[4][2], - periodic_dihedral_k_n_d_values[5][2], + periodic_dihedral_energy_check = ( + mdf_math.periodic_dihedral_n_1_2_3_4_5( + phi_values_for_check_degrees_list[opls_fit_i], + periodic_dihedral_k_n_d_values[0][0], + periodic_dihedral_k_n_d_values[1][0], + periodic_dihedral_k_n_d_values[2][0], + periodic_dihedral_k_n_d_values[3][0], + periodic_dihedral_k_n_d_values[4][0], + periodic_dihedral_k_n_d_values[5][0], + periodic_dihedral_k_n_d_values[0][1], + periodic_dihedral_k_n_d_values[1][1], + periodic_dihedral_k_n_d_values[2][1], + periodic_dihedral_k_n_d_values[3][1], + periodic_dihedral_k_n_d_values[4][1], + periodic_dihedral_k_n_d_values[5][1], + periodic_dihedral_k_n_d_values[0][2], + periodic_dihedral_k_n_d_values[1][2], + periodic_dihedral_k_n_d_values[2][2], + periodic_dihedral_k_n_d_values[3][2], + periodic_dihedral_k_n_d_values[4][2], + periodic_dihedral_k_n_d_values[5][2], + ) ) # check periodic dihedral equation fit matches the OPLS value - if not math.isclose(opls_dihedral_energy_check, periodic_dihedral_energy_check): + if not math.isclose( + opls_dihedral_energy_check, periodic_dihedral_energy_check + ): raise ValueError( "ERROR: The OPLS and periodic/CHARMM style dihedral energies do not match. " "The is likely a conversion error in the the constants between OPLS and the periodic/CHARMM style." @@ -2108,7 +2326,7 @@ def fit_dihedral_with_gomc( opls_fit_data_k1_kcal_per_mol_list[opls_fit_i], opls_fit_data_k2_kcal_per_mol_list[opls_fit_i], opls_fit_data_k3_kcal_per_mol_list[opls_fit_i], - opls_fit_data_k4_kcal_per_mol_list[opls_fit_i] + opls_fit_data_k4_kcal_per_mol_list[opls_fit_i], ) RB_torsion_energy_check = mdf_math.RB_torsion_n_1_2_3_4_5( @@ -2118,12 +2336,13 @@ def fit_dihedral_with_gomc( RB_torsion_k_values[2], RB_torsion_k_values[3], RB_torsion_k_values[4], - RB_torsion_k_values[5] - + RB_torsion_k_values[5], ) # check periodic dihedral equation fit matches the OPLS value - if not math.isclose(opls_dihedral_energy_check, RB_torsion_energy_check): + if not math.isclose( + opls_dihedral_energy_check, RB_torsion_energy_check + ): raise ValueError( "ERROR: The OPLS dihedral and RB torsion style energies do not match. " "The is likely a conversion error in the the constants between OPLS dihedral and RB torsion style." @@ -2205,35 +2424,41 @@ def fit_dihedral_with_gomc( # ********************************* opls_k_constant_fitted_q_list = [] opls_r_squared_fitted_data_via_gomc_list = [] - for opls_q, opls_fit_q in enumerate(opls_fit_data_non_zero_k_constants_list): - - gomc_fitted_gaussian_kcal_mol_energy_filename = \ + for opls_q, opls_fit_q in enumerate( + opls_fit_data_non_zero_k_constants_list + ): + gomc_fitted_gaussian_kcal_mol_energy_filename = ( f"all_normalized_energies_OPLS_fit_{opls_fit_q}_in_kcal_per_mol.txt" + ) # write the GOMC control files for scan_iter_q in range(1, len(Guassian_raw_degrees_list) + 1): - read_gomc_fitted_restart_file_coor_dir_and_name = \ - f'../{xyz_xsc_coor_files_directory}/dihedral_coords_position_{scan_iter_q}.coor' - read_gomc_fitted_restart_file_xsc_dir_and_name = f'../{xyz_xsc_coor_files_directory}/starting_point.xsc' + read_gomc_fitted_restart_file_coor_dir_and_name = f"../{xyz_xsc_coor_files_directory}/dihedral_coords_position_{scan_iter_q}.coor" + read_gomc_fitted_restart_file_xsc_dir_and_name = ( + f"../{xyz_xsc_coor_files_directory}/starting_point.xsc" + ) # The gomc raw energy filename in Kelvin Energies - gomc_raw_energy_fitted_filename = f"gomc_raw_OPLS_fit_{opls_fit_q}_energies_in_Kelvin.txt" + gomc_raw_energy_fitted_filename = ( + f"gomc_raw_OPLS_fit_{opls_fit_q}_energies_in_Kelvin.txt" + ) # The combined GOMC and Gaussian dihedral angles and energies in kcal/mol - gomc_gaussian_kcal_mol_energy_fitted_filename = \ - f"all_normalized_OPLS_fit_{opls_fit_q}_energies_in_kcal_per_mol.txt" + gomc_gaussian_kcal_mol_energy_fitted_filename = f"all_normalized_OPLS_fit_{opls_fit_q}_energies_in_kcal_per_mol.txt" - control_file_name_fitted_str = f'GOMC_OPLS_fit_{opls_fit_q}_dihedral_coords_{scan_iter_q}.conf' - output_name_control_fitted_file_name_str = \ - f'output_GOMC_OPLS_fit_{opls_fit_q}_dihedral_coords_{scan_iter_q}.txt' + control_file_name_fitted_str = ( + f"GOMC_OPLS_fit_{opls_fit_q}_dihedral_coords_{scan_iter_q}.conf" + ) + output_name_control_fitted_file_name_str = f"output_GOMC_OPLS_fit_{opls_fit_q}_dihedral_coords_{scan_iter_q}.txt" print("#**********************") print( - "Started: Writing NVT GOMC control file for the GOMC simulation with fitted dihedral k values.") + "Started: Writing NVT GOMC control file for the GOMC simulation with fitted dihedral k values." + ) print("#**********************") gomc_control.write_gomc_control_file( charmm, - f'{gomc_runs_folder_name}/{control_file_name_fitted_str}', - 'NVT', + f"{gomc_runs_folder_name}/{control_file_name_fitted_str}", + "NVT", MC_steps, temperature_unyt_units, ff_psf_pdb_file_directory=None, @@ -2288,7 +2513,9 @@ def fit_dihedral_with_gomc( }, ) print("#**********************") - print("Completed: NVT GOMC control file written for the GOMC simulation with fitted dihedral k values.") + print( + "Completed: NVT GOMC control file written for the GOMC simulation with fitted dihedral k values." + ) print("#**********************") # ************************************************************** @@ -2305,8 +2532,8 @@ def fit_dihedral_with_gomc( ] mdf_frw.change_gomc_ff_file_dihedral_values( - f'{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_per_xml.inp', - f'{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_OPLS_fit_{opls_fit_q}_dihedral.inp', + f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_dihedrals_per_xml.inp", + f"{gomc_runs_folder_name}/{output_gomc_pdb_psf_ff_file_name_str}_OPLS_fit_{opls_fit_q}_dihedral.inp", fit_dihedral_atom_types, fit_dihedral_opls_k_0_1_2_3_4_values=opls_k_constant_fitted_q_list, zeroed_dihedral_atom_types=zeroed_dihedral_atom_types, @@ -2317,9 +2544,10 @@ def fit_dihedral_with_gomc( # ************************************************************** # only run NVT as we only want/need the initial energy and want the box a constant size - run_gomc_command = \ - f"cd {gomc_runs_folder_name} && {gomc_binary_path}/GOMC_CPU_NVT +p{gomc_cpu_cores} " \ + run_gomc_command = ( + f"cd {gomc_runs_folder_name} && {gomc_binary_path}/GOMC_CPU_NVT +p{gomc_cpu_cores} " f"{control_file_name_fitted_str} > {output_name_control_fitted_file_name_str}" + ) exec_gomc_run_command = subprocess.Popen( run_gomc_command, shell=True, stderr=subprocess.STDOUT @@ -2335,37 +2563,52 @@ def fit_dihedral_with_gomc( # open the gomc raw energy file so it can be writen over in the loop read_gomc_log_fitted_file = open( - f'{gomc_runs_folder_name}/{output_name_control_fitted_file_name_str}', "r" + f"{gomc_runs_folder_name}/{output_name_control_fitted_file_name_str}", + "r", ).readlines() get_e_titles = True - for log_file_iter, log_file_line_iter in enumerate(read_gomc_log_fitted_file): + for log_file_iter, log_file_line_iter in enumerate( + read_gomc_log_fitted_file + ): log_file_splitline_iter = log_file_line_iter.split() # scan_iter starts at 1 - dihedral_angle_degrees = Guassian_raw_degrees_list[scan_iter_q - 1] + dihedral_angle_degrees = Guassian_raw_degrees_list[ + scan_iter_q - 1 + ] # only open the gomc raw energy file and write header for 1st iteration (1) if len(log_file_splitline_iter) >= 2: - if scan_iter_q == 1 and log_file_splitline_iter[0] == "ETITLE:" and get_e_titles is True: + if ( + scan_iter_q == 1 + and log_file_splitline_iter[0] == "ETITLE:" + and get_e_titles is True + ): gomc_combined_raw_fitted_energy = open( - gomc_raw_energy_fitted_filename, "w") + gomc_raw_energy_fitted_filename, "w" + ) # remove the wrongly entered 5 spaces in before "ETITLE: # (This will be fixed in GOMC so it is not required) extra_spaces_for_header_space_gomc_bug = 5 - gomc_combined_raw_fitted_energy.write(f'{"Dihedral_Position": <19} ' - f'{"Dihedral_Degrees": <19} ' - f'{log_file_line_iter[extra_spaces_for_header_space_gomc_bug:]}' - ) + gomc_combined_raw_fitted_energy.write( + f'{"Dihedral_Position": <19} ' + f'{"Dihedral_Degrees": <19} ' + f"{log_file_line_iter[extra_spaces_for_header_space_gomc_bug:]}" + ) if get_e_titles is True: get_e_titles = False # get only the initial configuration energy lin (i.e., step 0 line) - if log_file_splitline_iter[0] == 'ENER_0:' and log_file_splitline_iter[1] == '0': - gomc_combined_raw_fitted_energy.write(f'{scan_iter_q: <19}' - f'{dihedral_angle_degrees: <19} ' - f'{log_file_line_iter[5:]}' - ) + if ( + log_file_splitline_iter[0] == "ENER_0:" + and log_file_splitline_iter[1] == "0" + ): + gomc_combined_raw_fitted_energy.write( + f"{scan_iter_q: <19}" + f"{dihedral_angle_degrees: <19} " + f"{log_file_line_iter[5:]}" + ) # This fails when the GOMC simulations did not run try: @@ -2373,31 +2616,42 @@ def fit_dihedral_with_gomc( gomc_combined_raw_fitted_energy.close() except: - raise ValueError("ERROR: The GOMC fit test simulations did not run. " - "There is likely an error in creating the " - "required GOMC test simulations files or user inputs to the desired files.") + raise ValueError( + "ERROR: The GOMC fit test simulations did not run. " + "There is likely an error in creating the " + "required GOMC test simulations files or user inputs to the desired files." + ) # extract the raw data - GOMC_data_fitted_df = pd.DataFrame(pd.read_csv( - gomc_raw_energy_fitted_filename, sep='\s+')) - GOMC_data_fitted_dihedral_degrees_list = GOMC_data_fitted_df.loc[:, 'Dihedral_Degrees'].tolist( - ) - GOMC_data_fitted_total_energy_K_list = GOMC_data_fitted_df.loc[:, 'TOTAL'].tolist( + GOMC_data_fitted_df = pd.DataFrame( + pd.read_csv(gomc_raw_energy_fitted_filename, sep="\s+") ) + GOMC_data_fitted_dihedral_degrees_list = GOMC_data_fitted_df.loc[ + :, "Dihedral_Degrees" + ].tolist() + GOMC_data_fitted_total_energy_K_list = GOMC_data_fitted_df.loc[ + :, "TOTAL" + ].tolist() print( - f'GOMC_data_fitted_dihedral_degrees_list = {GOMC_data_fitted_dihedral_degrees_list}') + f"GOMC_data_fitted_dihedral_degrees_list = {GOMC_data_fitted_dihedral_degrees_list}" + ) print( - f'GOMC_data_fitted_total_energy_K_list = {GOMC_data_fitted_total_energy_K_list}') + f"GOMC_data_fitted_total_energy_K_list = {GOMC_data_fitted_total_energy_K_list}" + ) # convert from Kelvin to kcal/mol normalize so the min value is 0 - GOMC_data_fitted_total_energy_kcal_per_mol_list = \ - [i * conversion_K_to_kcal_per_mol for i in GOMC_data_fitted_total_energy_K_list] - GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list = \ - [i - min(GOMC_data_fitted_total_energy_kcal_per_mol_list) - for i in GOMC_data_fitted_total_energy_kcal_per_mol_list] + GOMC_data_fitted_total_energy_kcal_per_mol_list = [ + i * conversion_K_to_kcal_per_mol + for i in GOMC_data_fitted_total_energy_K_list + ] + GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list = [ + i - min(GOMC_data_fitted_total_energy_kcal_per_mol_list) + for i in GOMC_data_fitted_total_energy_kcal_per_mol_list + ] print( - f'GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list = {GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list}') + f"GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list = {GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list}" + ) # ********************************* # get GOMC data (END) @@ -2407,56 +2661,77 @@ def fit_dihedral_with_gomc( # get Gaussian data (START) # ********************************* # extract the raw data - Guassian_data_df = pd.DataFrame(pd.read_csv( - qm_energy_file_dir_and_name, sep='\s+', header=3)) - Guassian_data_fitted_dihedral_degrees_list = Guassian_data_df.iloc[:, 0].tolist( - ) - Guassian_data_total_energy_Hartree_list = Guassian_data_df.iloc[:, 1].tolist( + Guassian_data_df = pd.DataFrame( + pd.read_csv(qm_energy_file_dir_and_name, sep="\s+", header=3) ) + Guassian_data_fitted_dihedral_degrees_list = Guassian_data_df.iloc[ + :, 0 + ].tolist() + Guassian_data_total_energy_Hartree_list = Guassian_data_df.iloc[ + :, 1 + ].tolist() # convert from Hartree to kcal/mol energy units - Guassian_data_total_energy_kcal_per_mol_list = \ - [i * conversion_hartree_to_kcal_per_mol for i in Guassian_data_total_energy_Hartree_list] + Guassian_data_total_energy_kcal_per_mol_list = [ + i * conversion_hartree_to_kcal_per_mol + for i in Guassian_data_total_energy_Hartree_list + ] # normalize so the min value is 0 - Guassian_data_total_energy_kcal_per_mol_normalize_list = \ - [i - min(Guassian_data_total_energy_kcal_per_mol_list) for i in - Guassian_data_total_energy_kcal_per_mol_list] + Guassian_data_total_energy_kcal_per_mol_normalize_list = [ + i - min(Guassian_data_total_energy_kcal_per_mol_list) + for i in Guassian_data_total_energy_kcal_per_mol_list + ] # get the Gaussian minus GOMC total energy and then it normalized - Gaussian_minus_GOMC_data_fitted_dihedral_degrees_list = GOMC_data_fitted_dihedral_degrees_list + Gaussian_minus_GOMC_data_fitted_dihedral_degrees_list = ( + GOMC_data_fitted_dihedral_degrees_list + ) Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list = [ Guassian_data_total_energy_kcal_per_mol_normalize_list[i] - GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list[i] - for i in range(0, len(Guassian_data_total_energy_kcal_per_mol_normalize_list)) + for i in range( + 0, len(Guassian_data_total_energy_kcal_per_mol_normalize_list) + ) ] Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_normalized_list = [ - Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list[i] - - min(Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list) - for i in range(0, len(Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list)) + Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list[i] + - min( + Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list + ) + for i in range( + 0, + len( + Gaussian_minus_GOMC_data_fitted_total_energy_kcal_per_mol_list + ), + ) ] # get R**2 for the fit, running through GOMC to get the new energy of the # individual fit. opls_r_squared_fitted_data_via_gomc_iter = mdf_math.get_r_squared( Guassian_data_total_energy_kcal_per_mol_normalize_list, - GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list + GOMC_data_fitted_total_energy_kcal_per_mol_normalize_list, ) opls_r_squared_fitted_data_via_gomc_list.append( - opls_r_squared_fitted_data_via_gomc_iter) + opls_r_squared_fitted_data_via_gomc_iter + ) # Use R**2 (R-squared) to compare the data used to fit the dihedral(s) # via a single or multi-dihedral fit, to the individual fit entered in # GOMC and then recompared to Gaussian and write out the data to a file. print(f"*****************") - print(f"GOMC_data_fitted_dihedral_degrees_list === {len(GOMC_data_fitted_dihedral_degrees_list)}") + print( + f"GOMC_data_fitted_dihedral_degrees_list === {len(GOMC_data_fitted_dihedral_degrees_list)}" + ) print(f"*****************") for q_angle in range(0, len(GOMC_data_fitted_dihedral_degrees_list)): if q_angle == 0: # write out the GOMC and Gaussian data in a file - gomc_fitted_gaussian_kcal_mol_energy_data_txt_file = \ - open(gomc_fitted_gaussian_kcal_mol_energy_filename, "w") + gomc_fitted_gaussian_kcal_mol_energy_data_txt_file = open( + gomc_fitted_gaussian_kcal_mol_energy_filename, "w" + ) gomc_fitted_gaussian_kcal_mol_energy_data_txt_file.write( f"{'Dihedral_Degrees': <30} " f"{'GOMC_E_kcal_per_mol': <30} " @@ -2479,19 +2754,20 @@ def fit_dihedral_with_gomc( f"{str(opls_k_constant_fitted_q_list[2]): <30} " f"{str(opls_k_constant_fitted_q_list[3]): <30} " f"{str(opls_k_constant_fitted_q_list[4]): <30} " - ) + ) # Compare original fit vs run through GOMC as a validation test case - if opls_fit_data_r_squared_list[opls_q] >= fit_min_validated_r_squared \ - and not np.isclose( - opls_r_squared_fitted_data_via_gomc_list[opls_q], - opls_fit_data_r_squared_list[opls_q], - rtol=fit_validation_r_squared_rtol + if opls_fit_data_r_squared_list[ + opls_q + ] >= fit_min_validated_r_squared and not np.isclose( + opls_r_squared_fitted_data_via_gomc_list[opls_q], + opls_fit_data_r_squared_list[opls_q], + rtol=fit_validation_r_squared_rtol, ): raise ValueError( f"ERROR: The calculated R-squared energy values from the fit type " f"{opls_fit_data_non_zero_k_constants_list[opls_q]} " - f"does not match the validated case for 'fit_min_validated_r_squared' >= " \ + f"does not match the validated case for 'fit_min_validated_r_squared' >= " f"{mdf_math.round_to_sig_figs(fit_min_validated_r_squared,sig_figs=8)}, " f"within the relative tolerance or 'fit_validation_r_squared_rtol' = " f"{mdf_math.round_to_sig_figs(fit_validation_r_squared_rtol,sig_figs=8)}. \n" @@ -2522,8 +2798,8 @@ def fit_dihedral_with_gomc( fig2, (ax2) = plt.subplots(1) axis_Label_font_size = 12 legend_font_size = 12 - ax2.set_xlabel('phi (degrees)', size=axis_Label_font_size) - ax2.set_ylabel('Dihedral Energy (kcal/mol)', size=axis_Label_font_size) + ax2.set_xlabel("phi (degrees)", size=axis_Label_font_size) + ax2.set_ylabel("Dihedral Energy (kcal/mol)", size=axis_Label_font_size) plt.title( "OPLS: All viable individual dihedral fits. \n " @@ -2544,7 +2820,8 @@ def fit_dihedral_with_gomc( phi_degrees_list_iter.append(-180 + j * delta_phi_degrees_iter) cos_power_list_iter.append( - opls_fit_data_non_zero_k_constants_list[opls_fit_j]) + opls_fit_data_non_zero_k_constants_list[opls_fit_j] + ) opls_dihedral_energy_iter = mdf_math.opls_dihedral( ( @@ -2554,13 +2831,13 @@ def fit_dihedral_with_gomc( None, None, None, - None + None, ), opls_fit_data_k0_kcal_per_mol_list[opls_fit_j], opls_fit_data_k1_kcal_per_mol_list[opls_fit_j], opls_fit_data_k2_kcal_per_mol_list[opls_fit_j], opls_fit_data_k3_kcal_per_mol_list[opls_fit_j], - opls_fit_data_k4_kcal_per_mol_list[opls_fit_j] + opls_fit_data_k4_kcal_per_mol_list[opls_fit_j], ) opls_dihedral_energy_list_iter.append(opls_dihedral_energy_iter) @@ -2570,9 +2847,9 @@ def fit_dihedral_with_gomc( plt.plot( np.asarray(phi_degrees_list_iter), np.asarray(opls_dihedral_energy_list_iter), - '-', + "-", label=f" {opls_fit_data_non_zero_k_constants_list[opls_fit_j]} " - f"| $R^{2}$={np.round(opls_r_squared_fitted_data_via_gomc_list[opls_fit_j], decimals=4)}" + f"| $R^{2}$={np.round(opls_r_squared_fitted_data_via_gomc_list[opls_fit_j], decimals=4)}", ) ax2.set_xticks(major_xticks) @@ -2583,7 +2860,7 @@ def fit_dihedral_with_gomc( ncol=2, loc="lower center", fontsize=legend_font_size, - prop={'family': 'Arial', 'size': legend_font_size} + prop={"family": "Arial", "size": legend_font_size}, ) ax2.set_xticks(major_xticks) @@ -2597,7 +2874,7 @@ def fit_dihedral_with_gomc( # plt.show() fig2.savefig( f"opls_{all_individual_fit_dihedral_k_constants_figure_filename}", - dpi=300 + dpi=300, ) # ************************************************************** # ************************************************************** diff --git a/mosdef_dihedral_fit/tests/test_fit_dihedral_with_gomc.py b/mosdef_dihedral_fit/tests/test_fit_dihedral_with_gomc.py index 4829fb2..baaf948 100644 --- a/mosdef_dihedral_fit/tests/test_fit_dihedral_with_gomc.py +++ b/mosdef_dihedral_fit/tests/test_fit_dihedral_with_gomc.py @@ -1,61 +1,165 @@ import os -import unyt as u + import pytest +import unyt as u + +import mosdef_dihedral_fit.utils.math_operations as mdf_math +from mosdef_dihedral_fit.dihedral_fit.fit_dihedral_with_gomc import ( + fit_dihedral_with_gomc, +) from mosdef_dihedral_fit.tests.base_test import BaseTest from mosdef_dihedral_fit.utils.io import get_mosdef_dihedral_fit_fn -from mosdef_dihedral_fit.dihedral_fit.fit_dihedral_with_gomc import fit_dihedral_with_gomc -import mosdef_dihedral_fit.utils.math_operations as mdf_math # user changable variable, as it needs to be run locally gomc_binary_directory = "/home/brad/Programs/GOMC/GOMC_2_75/bin" + class TestFitDihedralWithGomc(BaseTest): def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 - ) - - assert os.path.isfile('all_normalized_energies_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('gomc_raw_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('opls_all_single_fit_dihedral_k_constants_figure.pdf') is True - assert os.path.isfile('opls_all_summed_dihedrals_k_constants_figure.pdf') is True - assert os.path.isfile('opls_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('periodic_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('RB_torsion_k_constants_fit_energy.txt') is True + fit_validation_r_squared_rtol=1e-03, + ) + + assert ( + os.path.isfile("all_normalized_energies_in_kcal_per_mol.txt") + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt" + ) + is False + ) + assert os.path.isfile("gomc_raw_energies_in_Kelvin.txt") is True + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile( + "opls_all_single_fit_dihedral_k_constants_figure.pdf" + ) + is True + ) + assert ( + os.path.isfile("opls_all_summed_dihedrals_k_constants_figure.pdf") + is True + ) + assert ( + os.path.isfile("opls_dihedral_k_constants_fit_energy.txt") is True + ) + assert ( + os.path.isfile("periodic_dihedral_k_constants_fit_energy.txt") + is True + ) + assert os.path.isfile("RB_torsion_k_constants_fit_energy.txt") is True # check the OPLS dihedral file with open("opls_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -65,24 +169,15 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'r_squared' + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "r_squared", ], - [ - str(3), - 0, - 0, - 0, - 0.314003748427, - 0, - 0.998791145574 - ], - + [str(3), 0, 0, 0, 0.314003748427, 0, 0.998791145574], ] if i == 0: @@ -93,12 +188,17 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("periodic_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -108,29 +208,29 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'n0_kcal_per_mol', - 'n1_kcal_per_mol', - 'n2_kcal_per_mol', - 'n3_kcal_per_mol', - 'n4_kcal_per_mol', - 'n5_kcal_per_mol', - 'd0_kcal_per_mol', - 'd1_kcal_per_mol', - 'd2_kcal_per_mol', - 'd3_kcal_per_mol', - 'd4_kcal_per_mol', - 'd5_kcal_per_mol', - 'r_squared', - ], - [ - str('0_3'), + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "n0_kcal_per_mol", + "n1_kcal_per_mol", + "n2_kcal_per_mol", + "n3_kcal_per_mol", + "n4_kcal_per_mol", + "n5_kcal_per_mol", + "d0_kcal_per_mol", + "d1_kcal_per_mol", + "d2_kcal_per_mol", + "d3_kcal_per_mol", + "d4_kcal_per_mol", + "d5_kcal_per_mol", + "r_squared", + ], + [ + str("0_3"), 0.314003748427, 0, 0, @@ -149,9 +249,8 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): 180.0, 0, 180.0, - 0.998791145574 + 0.998791145574, ], - ] if i == 0: @@ -162,12 +261,17 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("RB_torsion_k_constants_fit_energy.txt", "r") as fp: @@ -177,26 +281,25 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'r_squared', + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "r_squared", ], [ - str('0_3'), + str("0_3"), 0.157001874212, 0.471005622638, 0, -0.62800749685, 0, 0, - 0.998791145574 + 0.998791145574, ], - ] if i == 0: @@ -207,62 +310,168 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC(self): for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - - def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(self): + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) + + def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files( + self, + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): [0], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 - ) - - assert os.path.isfile('all_normalized_energies_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt') is False - assert os.path.isfile('gomc_raw_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt') is False - assert os.path.isfile('opls_all_single_fit_dihedral_k_constants_figure.pdf') is True - assert os.path.isfile('opls_all_summed_dihedrals_k_constants_figure.pdf') is True - assert os.path.isfile('opls_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('periodic_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('RB_torsion_k_constants_fit_energy.txt') is True + fit_validation_r_squared_rtol=1e-03, + ) + + assert ( + os.path.isfile("all_normalized_energies_in_kcal_per_mol.txt") + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt" + ) + is False + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt" + ) + is False + ) + assert os.path.isfile("gomc_raw_energies_in_Kelvin.txt") is True + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt") + is False + ) + assert ( + os.path.isfile( + "opls_all_single_fit_dihedral_k_constants_figure.pdf" + ) + is True + ) + assert ( + os.path.isfile("opls_all_summed_dihedrals_k_constants_figure.pdf") + is True + ) + assert ( + os.path.isfile("opls_dihedral_k_constants_fit_energy.txt") is True + ) + assert ( + os.path.isfile("periodic_dihedral_k_constants_fit_energy.txt") + is True + ) + assert os.path.isfile("RB_torsion_k_constants_fit_energy.txt") is True # check the OPLS dihedral file with open("opls_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -272,24 +481,15 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'r_squared' - ], - [ - str(3), - 0, - 0, - 0, - 0.314003748425, - 0, - 0.998791145574 + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "r_squared", ], - + [str(3), 0, 0, 0, 0.314003748425, 0, 0.998791145574], ] if i == 0: @@ -300,12 +500,17 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("periodic_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -315,29 +520,29 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'n0_kcal_per_mol', - 'n1_kcal_per_mol', - 'n2_kcal_per_mol', - 'n3_kcal_per_mol', - 'n4_kcal_per_mol', - 'n5_kcal_per_mol', - 'd0_kcal_per_mol', - 'd1_kcal_per_mol', - 'd2_kcal_per_mol', - 'd3_kcal_per_mol', - 'd4_kcal_per_mol', - 'd5_kcal_per_mol', - 'r_squared', - ], - [ - str('0_3'), + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "n0_kcal_per_mol", + "n1_kcal_per_mol", + "n2_kcal_per_mol", + "n3_kcal_per_mol", + "n4_kcal_per_mol", + "n5_kcal_per_mol", + "d0_kcal_per_mol", + "d1_kcal_per_mol", + "d2_kcal_per_mol", + "d3_kcal_per_mol", + "d4_kcal_per_mol", + "d5_kcal_per_mol", + "r_squared", + ], + [ + str("0_3"), 0.314003748425, 0, 0, @@ -356,9 +561,8 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se 180.0, 0, 180.0, - 0.998791145574 + 0.998791145574, ], - ] if i == 0: @@ -369,12 +573,17 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("RB_torsion_k_constants_fit_energy.txt", "r") as fp: @@ -384,26 +593,25 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'r_squared', + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "r_squared", ], [ - str('0_3'), + str("0_3"), 0.157001874212, 0.471005622638, 0, -0.62800749685, 0, 0, - 0.998791145574 + 0.998791145574, ], - ] if i == 0: @@ -414,62 +622,162 @@ def test_gaussian_log_file_fit_oplsaa_fit_ethane_HC_CT_CT_HC_with_2_log_files(se for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - - - def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(self): + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) + + def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH( + self, + ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian/CT_CT_C_OH/input/starting_coords/protonated_fragment_CT_CT_C_OH_in_COOH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian/CT_CT_C_OH/input/starting_coords/protonated_fragment_CT_CT_C_OH_in_COOH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { get_mosdef_dihedral_fit_fn( - 'gaussian/CT_CT_C_OH/output/CT_CT_C_OH_multiplicity_1.log'): [0], + "gaussian/CT_CT_C_OH/output/CT_CT_C_OH_multiplicity_1.log" + ): [0], }, - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3']], + zeroed_dihedral_atom_types=[["CT", "CT", "C", "O_3"]], qm_engine="gaussian", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 - ) - - assert os.path.isfile('all_normalized_energies_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('gomc_raw_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('opls_all_single_fit_dihedral_k_constants_figure.pdf') is True - assert os.path.isfile('opls_all_summed_dihedrals_k_constants_figure.pdf') is True - assert os.path.isfile('opls_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('periodic_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('RB_torsion_k_constants_fit_energy.txt') is True + fit_validation_r_squared_rtol=1e-03, + ) + + assert ( + os.path.isfile("all_normalized_energies_in_kcal_per_mol.txt") + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt" + ) + is True + ) + assert os.path.isfile("gomc_raw_energies_in_Kelvin.txt") is True + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile( + "opls_all_single_fit_dihedral_k_constants_figure.pdf" + ) + is True + ) + assert ( + os.path.isfile("opls_all_summed_dihedrals_k_constants_figure.pdf") + is True + ) + assert ( + os.path.isfile("opls_dihedral_k_constants_fit_energy.txt") is True + ) + assert ( + os.path.isfile("periodic_dihedral_k_constants_fit_energy.txt") + is True + ) + assert os.path.isfile("RB_torsion_k_constants_fit_energy.txt") is True # check the OPLS dihedral file with open("opls_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -479,105 +787,72 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'r_squared' - ], - [ - str('1'), - 0, - 2.0040856888, - 0, - 0, - 0, - -0.371866278201 - ], - [ - str('2'), - 0, - 0, - 2.13847194795, - 0, - 0, - 0.264787158812 - ], - [ - str('3'), - 0, - 0, - 0, - 1.79252468631, - 0, - -1.29046011346 - ], - [ - str('4'), - 0, - 0, - 0, - 0, - 1.71219173182, - -1.61245472957 + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "r_squared", ], + [str("1"), 0, 2.0040856888, 0, 0, 0, -0.371866278201], + [str("2"), 0, 0, 2.13847194795, 0, 0, 0.264787158812], + [str("3"), 0, 0, 0, 1.79252468631, 0, -1.29046011346], + [str("4"), 0, 0, 0, 0, 1.71219173182, -1.61245472957], [ - str('1_3'), + str("1_3"), 0, 1.45632365305, 0, 0.821642099981, 0, - 0.0570637738537 + 0.0570637738537, ], [ - str('2_4'), + str("2_4"), 0, 0, 1.79461739534, 0, 0.51578023092, - 0.433811455157 + 0.433811455157, ], [ - str('3_4'), + str("3_4"), 0, 0, 0, 1.17191599967, 0.93091304322, - -0.739857285933 + -0.739857285933, ], [ - str('1_2'), + str("1_2"), 0, 1.04119433365, 1.44434211955, 0, 0, - 0.953575526751 + 0.953575526751, ], [ - str('1_2_3'), + str("1_2_3"), 0, 0.925047594605, 1.32819621337, 0.290365264803, 0, - 0.998573206243 + 0.998573206243, ], [ - str('1_2_3_4'), + str("1_2_3_4"), 0, 0.914079355436, 1.3172277155, 0.279396891938, 0.0383892587007, - 0.999295535579 + 0.999295535579, ], - ] if i == 0: @@ -588,13 +863,17 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("periodic_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -604,29 +883,29 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'n0_kcal_per_mol', - 'n1_kcal_per_mol', - 'n2_kcal_per_mol', - 'n3_kcal_per_mol', - 'n4_kcal_per_mol', - 'n5_kcal_per_mol', - 'd0_kcal_per_mol', - 'd1_kcal_per_mol', - 'd2_kcal_per_mol', - 'd3_kcal_per_mol', - 'd4_kcal_per_mol', - 'd5_kcal_per_mol', - 'r_squared', - ], - [ - str('0_1'), + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "n0_kcal_per_mol", + "n1_kcal_per_mol", + "n2_kcal_per_mol", + "n3_kcal_per_mol", + "n4_kcal_per_mol", + "n5_kcal_per_mol", + "d0_kcal_per_mol", + "d1_kcal_per_mol", + "d2_kcal_per_mol", + "d3_kcal_per_mol", + "d4_kcal_per_mol", + "d5_kcal_per_mol", + "r_squared", + ], + [ + str("0_1"), 2.0040856888, -1.0020428444, 0, @@ -648,7 +927,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel -0.371866278201, ], [ - str('0_2'), + str("0_2"), 2.13847194795, 0, -1.06923597397, @@ -670,7 +949,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel 0.264787158812, ], [ - str('0_3'), + str("0_3"), 1.79252468631, 0, 0, @@ -692,7 +971,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel -1.29046011346, ], [ - str('0_4'), + str("0_4"), 1.71219173182, 0, 0, @@ -714,7 +993,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel -1.61245472957, ], [ - str('0_1_3'), + str("0_1_3"), 2.27796575303, -0.728161826525, 0, @@ -736,7 +1015,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel 0.0570637738537, ], [ - str('0_2_4'), + str("0_2_4"), 2.31039762626, 0, -0.8973086976, @@ -758,7 +1037,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel 0.433811455157, ], [ - str('0_3_4'), + str("0_3_4"), 2.10282904289, 0, 0, @@ -780,7 +1059,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel -0.739857285933, ], [ - str('0_1_2'), + str("0_1_2"), 2.4855364532, -0.520597166825, -0.722171059775, @@ -802,7 +1081,7 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel 0.953575526751, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 2.54360907278, -0.462523797302, -0.664098106685, @@ -823,9 +1102,8 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel 180.0, 0.998573206243, ], - [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 2.54909322157, -0.457039677718, -0.65861385775, @@ -856,13 +1134,17 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the RB torsion file with open("RB_torsion_k_constants_fit_energy.txt", "r") as fp: @@ -872,116 +1154,115 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'r_squared' + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "r_squared", ], [ - str('0_1'), + str("0_1"), 1.0020428444, -1.0020428444, 0, 0, 0, 0, - -0.371866278201 + -0.371866278201, ], [ - str('0_2'), + str("0_2"), 2.13847194795, 0, -2.13847194795, 0, 0, 0, - 0.264787158812 + 0.264787158812, ], [ - str('0_3'), + str("0_3"), 0.896262343155, 2.68878702946, 0, -3.58504937262, 0, 0, - -1.29046011346 + -1.29046011346, ], [ - str('0_4'), + str("0_4"), 0, 0, 6.84876692728, 0, -6.84876692728, 0, - -1.61245472957 + -1.61245472957, ], [ - str('0_1_3'), + str("0_1_3"), 1.13898287652, 0.504301323446, 0, -1.64328419996, 0, 0, - 0.0570637738537 + 0.0570637738537, ], [ - str('0_2_4'), + str("0_2_4"), 1.79461739534, 0, 0.26850352834, 0, -2.06312092368, 0, - 0.433811455157 + 0.433811455157, ], [ - str('0_3_4'), + str("0_3_4"), 0.585957999835, 1.7578739995, 3.72365217288, -2.34383199934, -3.72365217288, 0, - -0.739857285933 + -0.739857285933, ], [ - str('0_1_2'), + str("0_1_2"), 1.96493928638, -0.520597166825, -1.44434211955, 0, 0, 0, - 0.953575526751 + 0.953575526751, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 1.93590264307, -0.026975900098, -1.32819621337, -0.580730529606, 0, 0, - 0.998573206243 + 0.998573206243, ], [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 1.91396583919, -0.037944339811, -1.1636706807, -0.558793783876, -0.153557034803, 0, - 0.999295535579 + 0.999295535579, ], - ] if i == 0: @@ -992,61 +1273,163 @@ def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH(sel for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - - def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_point(self): + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) + + def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_point( + self, + ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH_zeroed.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH_zeroed.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], zeroed_dihedral_atom_types=None, qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 - ) - - assert os.path.isfile('all_normalized_energies_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('gomc_raw_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('opls_all_single_fit_dihedral_k_constants_figure.pdf') is True - assert os.path.isfile('opls_all_summed_dihedrals_k_constants_figure.pdf') is True - assert os.path.isfile('opls_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('periodic_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('RB_torsion_k_constants_fit_energy.txt') is True + fit_validation_r_squared_rtol=0.02, + ) + + assert ( + os.path.isfile("all_normalized_energies_in_kcal_per_mol.txt") + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt" + ) + is True + ) + assert os.path.isfile("gomc_raw_energies_in_Kelvin.txt") is True + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile( + "opls_all_single_fit_dihedral_k_constants_figure.pdf" + ) + is True + ) + assert ( + os.path.isfile("opls_all_summed_dihedrals_k_constants_figure.pdf") + is True + ) + assert ( + os.path.isfile("opls_dihedral_k_constants_fit_energy.txt") is True + ) + assert ( + os.path.isfile("periodic_dihedral_k_constants_fit_energy.txt") + is True + ) + assert os.path.isfile("RB_torsion_k_constants_fit_energy.txt") is True # check the OPLS dihedral file with open("opls_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -1056,105 +1439,72 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'r_squared' - ], - [ - str('1'), - 0, - 1.80634795241, - 0, - 0, - 0, - -0.268742410571 - ], - [ - str('2'), - 0, - 0, - 1.94879786206, - 0, - 0, - 0.448421126946 - ], - [ - str('3'), - 0, - 0, - 0, - 1.58083737128, - 0, - -1.50863674602 - ], - [ - str('4'), - 0, - 0, - 0, - 0, - 1.5121963942, - -1.54542980028 + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "r_squared", ], + [str("1"), 0, 1.80634795241, 0, 0, 0, -0.268742410571], + [str("2"), 0, 0, 1.94879786206, 0, 0, 0.448421126946], + [str("3"), 0, 0, 0, 1.58083737128, 0, -1.50863674602], + [str("4"), 0, 0, 0, 0, 1.5121963942, -1.54542980028], [ - str('1_3'), + str("1_3"), 0, 1.41759854611, 0, 0.618102768602, 0, - -0.00379371805915 + -0.00379371805915, ], [ - str('2_4'), + str("2_4"), 0, 0, 1.69725316221, 0, 0.37780223364, - 0.551946157778 + 0.551946157778, ], [ - str('3_4'), + str("3_4"), 0, 0, 0, 0.966769776613, 0.903643214082, - -0.897967473282 + -0.897967473282, ], [ - str('1_2'), + str("1_2"), 0, 0.882099545744, 1.34468116365, 0, 0, - 0.986743110285 + 0.986743110285, ], [ - str('1_2_3'), + str("1_2_3"), 0, 0.83099823616, 1.29385707544, 0.136793004885, 0, - 0.997926382517 + 0.997926382517, ], [ - str('1_2_3_4'), + str("1_2_3_4"), 0, 0.836836322925, 1.29869945716, 0.141702758859, -0.0179044297589, - 0.998103759798 + 0.998103759798, ], - ] if i == 0: @@ -1165,13 +1515,17 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("periodic_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -1181,29 +1535,29 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'n0_kcal_per_mol', - 'n1_kcal_per_mol', - 'n2_kcal_per_mol', - 'n3_kcal_per_mol', - 'n4_kcal_per_mol', - 'n5_kcal_per_mol', - 'd0_kcal_per_mol', - 'd1_kcal_per_mol', - 'd2_kcal_per_mol', - 'd3_kcal_per_mol', - 'd4_kcal_per_mol', - 'd5_kcal_per_mol', - 'r_squared', - ], - [ - str('0_1'), + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "n0_kcal_per_mol", + "n1_kcal_per_mol", + "n2_kcal_per_mol", + "n3_kcal_per_mol", + "n4_kcal_per_mol", + "n5_kcal_per_mol", + "d0_kcal_per_mol", + "d1_kcal_per_mol", + "d2_kcal_per_mol", + "d3_kcal_per_mol", + "d4_kcal_per_mol", + "d5_kcal_per_mol", + "r_squared", + ], + [ + str("0_1"), 1.80634795241, -0.903173976205, 0, @@ -1225,7 +1579,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin -0.268742410571, ], [ - str('0_2'), + str("0_2"), 1.94879786206, 0, -0.97439893103, @@ -1247,7 +1601,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin 0.448421126946, ], [ - str('0_3'), + str("0_3"), 1.58083737128, 0, 0, @@ -1269,7 +1623,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin -1.50863674602, ], [ - str('0_4'), + str("0_4"), 1.5121963942, 0, 0, @@ -1291,7 +1645,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin -1.54542980028, ], [ - str('0_1_3'), + str("0_1_3"), 2.03570131471, -0.708799273055, 0, @@ -1313,7 +1667,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin -0.00379371805915, ], [ - str('0_2_4'), + str("0_2_4"), 2.07505539585, 0, -0.848626581105, @@ -1335,7 +1689,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin 0.551946157778, ], [ - str('0_3_4'), + str("0_3_4"), 1.8704129907, 0, 0, @@ -1357,7 +1711,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin -0.897967473282, ], [ - str('0_1_2'), + str("0_1_2"), 2.22678070939, -0.441049772872, -0.672340581825, @@ -1379,7 +1733,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin 0.986743110285, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 2.26164831649, -0.415499118084, -0.64692853772, @@ -1400,9 +1754,8 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin 180.0, 0.997926382517, ], - [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 2.25933410919, -0.418418161462, -0.64934972858, @@ -1433,13 +1786,17 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the RB torsion file with open("RB_torsion_k_constants_fit_energy.txt", "r") as fp: @@ -1449,116 +1806,115 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'r_squared' + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "r_squared", ], [ - str('0_1'), + str("0_1"), 0.903173976205, -0.903173976205, 0, 0, 0, 0, - -0.268742410571 + -0.268742410571, ], [ - str('0_2'), + str("0_2"), 1.94879786206, 0, -1.94879786206, 0, 0, 0, - 0.448421126946 + 0.448421126946, ], [ - str('0_3'), + str("0_3"), 0.79041868564, 2.37125605692, 0, -3.16167474256, 0, 0, - -1.50863674602 + -1.50863674602, ], [ - str('0_4'), + str("0_4"), 0, 0, 6.0487855768, 0, -6.0487855768, 0, - -1.54542980028 + -1.54542980028, ], [ - str('0_1_3'), + str("0_1_3"), 1.01785065736, 0.218354879848, 0, -1.2362055372, 0, 0, - -0.00379371805915 + -0.00379371805915, ], [ - str('0_2_4'), + str("0_2_4"), 1.69725316221, 0, -0.18604422765, 0, -1.51120893456, 0, - 0.551946157778 + 0.551946157778, ], [ - str('0_3_4'), + str("0_3_4"), 0.483384888306, 1.45015466492, 3.61457285633, -1.93353955323, -3.61457285633, 0, - -0.897967473282 + -0.897967473282, ], [ - str('0_1_2'), + str("0_1_2"), 1.78573093652, -0.441049772872, -1.34468116365, 0, 0, 0, - 0.986743110285 + 0.986743110285, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 1.77775269597, -0.210309610756, -1.29385707544, -0.27358600977, 0, 0, - 0.997926382517 + 0.997926382517, ], [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 1.78796899805, -0.205864023174, -1.3703171762, -0.283405517718, 0.0716177190356, 0, - 0.998103759798 + 0.998103759798, ], - ] if i == 0: @@ -1569,62 +1925,161 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_missing_1st_poin for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH_zeroed.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH_zeroed.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH/output'): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH/output" + ): [], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], zeroed_dihedral_atom_types=None, qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=5e-03 - ) - - assert os.path.isfile('all_normalized_energies_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('gomc_raw_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('opls_all_single_fit_dihedral_k_constants_figure.pdf') is True - assert os.path.isfile('opls_all_summed_dihedrals_k_constants_figure.pdf') is True - assert os.path.isfile('opls_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('periodic_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('RB_torsion_k_constants_fit_energy.txt') is True + fit_validation_r_squared_rtol=5e-03, + ) + + assert ( + os.path.isfile("all_normalized_energies_in_kcal_per_mol.txt") + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt" + ) + is True + ) + assert os.path.isfile("gomc_raw_energies_in_Kelvin.txt") is True + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile( + "opls_all_single_fit_dihedral_k_constants_figure.pdf" + ) + is True + ) + assert ( + os.path.isfile("opls_all_summed_dihedrals_k_constants_figure.pdf") + is True + ) + assert ( + os.path.isfile("opls_dihedral_k_constants_fit_energy.txt") is True + ) + assert ( + os.path.isfile("periodic_dihedral_k_constants_fit_energy.txt") + is True + ) + assert os.path.isfile("RB_torsion_k_constants_fit_energy.txt") is True # check the OPLS dihedral file with open("opls_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -1634,105 +2089,72 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'r_squared' + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "r_squared", ], + [str("1"), 0, 1.87103578693, 0, 0, 0, -0.184214001408], + [str("2"), 0, 0, 2.01338731788, 0, 0, 0.468487865197], + [str("3"), 0, 0, 0, 1.64674772188, 0, -1.32197179229], + [str("4"), 0, 0, 0, 0, 1.5768734149, -1.35119291697], [ - str('1'), - 0, - 1.87103578693, - 0, - 0, - 0, - -0.184214001408 - ], - [ - str('2'), - 0, - 0, - 2.01338731788, - 0, - 0, - 0.468487865197 - ], - [ - str('3'), - 0, - 0, - 0, - 1.64674772188, - 0, - -1.32197179229 - ], - [ - str('4'), - 0, - 0, - 0, - 0, - 1.5768734149, - -1.35119291697 - ], - [ - str('1_3'), + str("1_3"), 0, 1.45815624076, 0, 0.656469146108, 0, - 0.0786991845116 + 0.0786991845116, ], [ - str('2_4'), + str("2_4"), 0, 0, 1.73604078977, 0, 0.416554745122, - 0.579202191408 + 0.579202191408, ], [ - str('3_4'), + str("3_4"), 0, 0, 0, 1.00514371097, 0.944164973554, - -0.735494529166 + -0.735494529166, ], [ - str('1_2'), + str("1_2"), 0, 0.920441371308, 1.38301174904, 0, 0, - 0.984123002941 + 0.984123002941, ], [ - str('1_2_3'), + str("1_2_3"), 0, 0.858889958603, 1.32179425273, 0.164766862242, 0, - 0.998396296125 + 0.998396296125, ], [ - str('1_2_3_4'), + str("1_2_3_4"), 0, 0.857564707345, 1.32069502687, 0.163652345714, 0.00406432148459, - 0.998404336839 + 0.998404336839, ], - ] if i == 0: @@ -1743,13 +2165,17 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("periodic_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -1759,29 +2185,29 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'n0_kcal_per_mol', - 'n1_kcal_per_mol', - 'n2_kcal_per_mol', - 'n3_kcal_per_mol', - 'n4_kcal_per_mol', - 'n5_kcal_per_mol', - 'd0_kcal_per_mol', - 'd1_kcal_per_mol', - 'd2_kcal_per_mol', - 'd3_kcal_per_mol', - 'd4_kcal_per_mol', - 'd5_kcal_per_mol', - 'r_squared', - ], - [ - str('0_1'), + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "n0_kcal_per_mol", + "n1_kcal_per_mol", + "n2_kcal_per_mol", + "n3_kcal_per_mol", + "n4_kcal_per_mol", + "n5_kcal_per_mol", + "d0_kcal_per_mol", + "d1_kcal_per_mol", + "d2_kcal_per_mol", + "d3_kcal_per_mol", + "d4_kcal_per_mol", + "d5_kcal_per_mol", + "r_squared", + ], + [ + str("0_1"), 1.87103578693, -0.935517893465, 0, @@ -1803,7 +2229,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): -0.184214001408, ], [ - str('0_2'), + str("0_2"), 2.01338731788, 0, -1.00669365894, @@ -1825,7 +2251,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): 0.468487865197, ], [ - str('0_3'), + str("0_3"), 1.64674772188, 0, 0, @@ -1847,7 +2273,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): -1.32197179229, ], [ - str('0_4'), + str("0_4"), 1.5768734149, 0, 0, @@ -1869,7 +2295,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): -1.35119291697, ], [ - str('0_1_3'), + str("0_1_3"), 2.11462538687, -0.72907812038, 0, @@ -1891,7 +2317,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): 0.0786991845116, ], [ - str('0_2_4'), + str("0_2_4"), 2.15259553489, 0, -0.868020394885, @@ -1913,7 +2339,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): 0.579202191408, ], [ - str('0_3_4'), + str("0_3_4"), 1.94930868452, 0, 0, @@ -1935,7 +2361,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): -0.735494529166, ], [ - str('0_1_2'), + str("0_1_2"), 2.30345312035, -0.460220685654, -0.69150587452, @@ -1957,7 +2383,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): 0.984123002941, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 2.34545107358, -0.429444979302, -0.660897126365, @@ -1978,9 +2404,8 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): 180.0, 0.998396296125, ], - [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 2.34597640141, -0.428782353672, -0.660347513435, @@ -2011,13 +2436,17 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the RB torsion file with open("RB_torsion_k_constants_fit_energy.txt", "r") as fp: @@ -2027,116 +2456,115 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'r_squared' + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "r_squared", ], [ - str('0_1'), + str("0_1"), 0.935517893465, -0.935517893465, 0, 0, 0, 0, - -0.184214001408 + -0.184214001408, ], [ - str('0_2'), + str("0_2"), 2.01338731788, 0, -2.01338731788, 0, 0, 0, - 0.468487865197 + 0.468487865197, ], [ - str('0_3'), + str("0_3"), 0.82337386094, 2.47012158282, 0, -3.29349544376, 0, 0, - -1.32197179229 + -1.32197179229, ], [ - str('0_4'), + str("0_4"), 0, 0, 6.3074936596, 0, -6.3074936596, 0, - -1.35119291697 + -1.35119291697, ], [ - str('0_1_3'), + str("0_1_3"), 1.05731269343, 0.255625598782, 0, -1.31293829222, 0, 0, - 0.0786991845116 + 0.0786991845116, ], [ - str('0_2_4'), + str("0_2_4"), 1.73604078977, 0, -0.069821809282, 0, -1.66621898049, 0, - 0.579202191408 + 0.579202191408, ], [ - str('0_3_4'), + str("0_3_4"), 0.502571855485, 1.50771556646, 3.77665989422, -2.01028742194, -3.77665989422, 0, - -0.735494529166 + -0.735494529166, ], [ - str('0_1_2'), + str("0_1_2"), 1.84323243469, -0.460220685654, -1.38301174904, 0, 0, 0, - 0.984123002941 + 0.984123002941, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 1.83362266315, -0.182294685938, -1.32179425273, -0.329533724484, 0, 0, - 0.998396296125 + 0.998396296125, ], [ - str('0_1_2_3_4'), - 1.8313035534 , + str("0_1_2_3_4"), + 1.8313035534, -0.183303835102, -1.30443774093, -0.327304691428, -0.0162572859384, 0, - 0.998404336839 + 0.998404336839, ], - ] if i == 0: @@ -2147,63 +2575,166 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH(self): for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - - - def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_1_first_point(self): + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) + + def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_1_first_point( + self, + ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3']], + zeroed_dihedral_atom_types=[["CT", "CT", "C", "O_3"]], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 - ) - - assert os.path.isfile('all_normalized_energies_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt') is True - assert os.path.isfile('all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt') is True - assert os.path.isfile('gomc_raw_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt') is True - assert os.path.isfile('gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt') is True - assert os.path.isfile('opls_all_single_fit_dihedral_k_constants_figure.pdf') is True - assert os.path.isfile('opls_all_summed_dihedrals_k_constants_figure.pdf') is True - assert os.path.isfile('opls_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('periodic_dihedral_k_constants_fit_energy.txt') is True - assert os.path.isfile('RB_torsion_k_constants_fit_energy.txt') is True + fit_validation_r_squared_rtol=0.02, + ) + + assert ( + os.path.isfile("all_normalized_energies_in_kcal_per_mol.txt") + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_1_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_2_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_4_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_3_in_kcal_per_mol.txt" + ) + is True + ) + assert ( + os.path.isfile( + "all_normalized_energies_OPLS_fit_4_in_kcal_per_mol.txt" + ) + is True + ) + assert os.path.isfile("gomc_raw_energies_in_Kelvin.txt") is True + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_2_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_3_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_1_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_2_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_4_energies_in_Kelvin.txt") + is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_3_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile("gomc_raw_OPLS_fit_4_energies_in_Kelvin.txt") is True + ) + assert ( + os.path.isfile( + "opls_all_single_fit_dihedral_k_constants_figure.pdf" + ) + is True + ) + assert ( + os.path.isfile("opls_all_summed_dihedrals_k_constants_figure.pdf") + is True + ) + assert ( + os.path.isfile("opls_dihedral_k_constants_fit_energy.txt") is True + ) + assert ( + os.path.isfile("periodic_dihedral_k_constants_fit_energy.txt") + is True + ) + assert os.path.isfile("RB_torsion_k_constants_fit_energy.txt") is True # check the OPLS dihedral file with open("opls_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -2213,105 +2744,72 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'r_squared' - ], - [ - str('1'), - 0, - 1.80634795241, - 0, - 0, - 0, - -0.268742410571 - ], - [ - str('2'), - 0, - 0, - 1.94879786206, - 0, - 0, - 0.448421126946 - ], - [ - str('3'), - 0, - 0, - 0, - 1.58083737128, - 0, - -1.50863674602 - ], - [ - str('4'), - 0, - 0, - 0, - 0, - 1.5121963942, - -1.54542980028 + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "r_squared", ], + [str("1"), 0, 1.80634795241, 0, 0, 0, -0.268742410571], + [str("2"), 0, 0, 1.94879786206, 0, 0, 0.448421126946], + [str("3"), 0, 0, 0, 1.58083737128, 0, -1.50863674602], + [str("4"), 0, 0, 0, 0, 1.5121963942, -1.54542980028], [ - str('1_3'), + str("1_3"), 0, 1.41759854611, 0, 0.618102768602, 0, - -0.00379371805915 + -0.00379371805915, ], [ - str('2_4'), + str("2_4"), 0, 0, 1.69725316221, 0, 0.37780223364, - 0.551946157778 + 0.551946157778, ], [ - str('3_4'), + str("3_4"), 0, 0, 0, 0.966769776613, 0.903643214082, - -0.897967473282 + -0.897967473282, ], [ - str('1_2'), + str("1_2"), 0, 0.882099545744, 1.34468116365, 0, 0, - 0.986743110285 + 0.986743110285, ], [ - str('1_2_3'), + str("1_2_3"), 0, 0.83099823616, 1.29385707544, 0.136793004885, 0, - 0.997926382517 + 0.997926382517, ], [ - str('1_2_3_4'), + str("1_2_3_4"), 0, 0.836836322925, 1.29869945716, 0.141702758859, -0.0179044297589, - 0.998103759798 + 0.998103759798, ], - ] if i == 0: @@ -2322,13 +2820,17 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the periodic dihedral file with open("periodic_dihedral_k_constants_fit_energy.txt", "r") as fp: @@ -2338,29 +2840,29 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'n0_kcal_per_mol', - 'n1_kcal_per_mol', - 'n2_kcal_per_mol', - 'n3_kcal_per_mol', - 'n4_kcal_per_mol', - 'n5_kcal_per_mol', - 'd0_kcal_per_mol', - 'd1_kcal_per_mol', - 'd2_kcal_per_mol', - 'd3_kcal_per_mol', - 'd4_kcal_per_mol', - 'd5_kcal_per_mol', - 'r_squared', - ], - [ - str('0_1'), + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "n0_kcal_per_mol", + "n1_kcal_per_mol", + "n2_kcal_per_mol", + "n3_kcal_per_mol", + "n4_kcal_per_mol", + "n5_kcal_per_mol", + "d0_kcal_per_mol", + "d1_kcal_per_mol", + "d2_kcal_per_mol", + "d3_kcal_per_mol", + "d4_kcal_per_mol", + "d5_kcal_per_mol", + "r_squared", + ], + [ + str("0_1"), 1.80634795241, -0.903173976205, 0, @@ -2382,7 +2884,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ -0.268742410571, ], [ - str('0_2'), + str("0_2"), 1.94879786206, 0, -0.97439893103, @@ -2404,7 +2906,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ 0.448421126946, ], [ - str('0_3'), + str("0_3"), 1.58083737128, 0, 0, @@ -2426,7 +2928,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ -1.50863674602, ], [ - str('0_4'), + str("0_4"), 1.5121963942, 0, 0, @@ -2448,7 +2950,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ -1.54542980028, ], [ - str('0_1_3'), + str("0_1_3"), 2.03570131471, -0.708799273055, 0, @@ -2470,7 +2972,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ -0.00379371805915, ], [ - str('0_2_4'), + str("0_2_4"), 2.07505539585, 0, -0.848626581105, @@ -2492,7 +2994,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ 0.551946157778, ], [ - str('0_3_4'), + str("0_3_4"), 1.8704129907, 0, 0, @@ -2514,7 +3016,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ -0.897967473282, ], [ - str('0_1_2'), + str("0_1_2"), 2.22678070939, -0.441049772872, -0.672340581825, @@ -2536,7 +3038,7 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ 0.986743110285, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 2.26164831649, -0.415499118084, -0.64692853772, @@ -2557,9 +3059,8 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ 180.0, 0.997926382517, ], - [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 2.25933410919, -0.418418161462, -0.64934972858, @@ -2590,13 +3091,17 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) # check the RB torsion file with open("RB_torsion_k_constants_fit_energy.txt", "r") as fp: @@ -2606,116 +3111,115 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ split_line_i = line.split() correct_line_values = [ [ - 'non_zero_k_constants', - 'k0_kcal_per_mol', - 'k1_kcal_per_mol', - 'k2_kcal_per_mol', - 'k3_kcal_per_mol', - 'k4_kcal_per_mol', - 'k5_kcal_per_mol', - 'r_squared' + "non_zero_k_constants", + "k0_kcal_per_mol", + "k1_kcal_per_mol", + "k2_kcal_per_mol", + "k3_kcal_per_mol", + "k4_kcal_per_mol", + "k5_kcal_per_mol", + "r_squared", ], [ - str('0_1'), + str("0_1"), 0.903173976205, -0.903173976205, 0, 0, 0, 0, - -0.268742410571 + -0.268742410571, ], [ - str('0_2'), + str("0_2"), 1.94879786206, 0, -1.94879786206, 0, 0, 0, - 0.448421126946 + 0.448421126946, ], [ - str('0_3'), + str("0_3"), 0.79041868564, 2.37125605692, 0, -3.16167474256, 0, 0, - -1.50863674602 + -1.50863674602, ], [ - str('0_4'), + str("0_4"), 0, 0, 6.0487855768, 0, -6.0487855768, 0, - -1.54542980028 + -1.54542980028, ], [ - str('0_1_3'), + str("0_1_3"), 1.01785065736, 0.218354879848, 0, -1.2362055372, 0, 0, - -0.00379371805915 + -0.00379371805915, ], [ - str('0_2_4'), + str("0_2_4"), 1.69725316221, 0, -0.18604422765, 0, -1.51120893456, 0, - 0.551946157778 + 0.551946157778, ], [ - str('0_3_4'), + str("0_3_4"), 0.483384888306, 1.45015466492, 3.61457285633, -1.93353955323, -3.61457285633, 0, - -0.897967473282 + -0.897967473282, ], [ - str('0_1_2'), + str("0_1_2"), 1.78573093652, -0.441049772872, -1.34468116365, 0, 0, 0, - 0.986743110285 + 0.986743110285, ], [ - str('0_1_2_3'), + str("0_1_2_3"), 1.77775269597, -0.210309610756, -1.29385707544, -0.27358600977, 0, 0, - 0.997926382517 + 0.997926382517, ], [ - str('0_1_2_3_4'), + str("0_1_2_3_4"), 1.78796899805, -0.205864023174, -1.3703171762, -0.283405517718, 0.0716177190356, 0, - 0.998103759798 + 0.998103759798, ], - ] if i == 0: @@ -2726,96 +3230,125 @@ def test_gaussian_style_files_fit_oplsaa_fit_CT_CT_C_OH_in_COOH_2_files_missing_ for j in range(0, len(correct_line_values[i])): # check the string listing what cosin powers are used if j == 0: - assert str(split_line_i[j]) == str(correct_line_values[i][j]) + assert str(split_line_i[j]) == str( + correct_line_values[i][j] + ) # check the k-values and the r-squared fit else: - assert mdf_math.round_to_sig_figs(float(split_line_i[j]), number_sig_i) == \ - mdf_math.round_to_sig_figs(correct_line_values[i][j], number_sig_i) - - def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH_bad_element_order_mol2(self): - mol2_elements_values = "\['C', 'C', 'O', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" - qm_elements_values = "\['C', 'C', 'C', 'O', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" + assert mdf_math.round_to_sig_figs( + float(split_line_i[j]), number_sig_i + ) == mdf_math.round_to_sig_figs( + correct_line_values[i][j], number_sig_i + ) + + def test_gaussian_log_file_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH_bad_element_order_mol2( + self, + ): + mol2_elements_values = ( + "\['C', 'C', 'O', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" + ) + qm_elements_values = ( + "\['C', 'C', 'C', 'O', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" + ) with pytest.raises( - ValueError, - match=f"ERROR: The QM elements do not match the mol2 file elements, in order. \n" - f"This does not guarantee that the element postions are correct. \n" - f"mol2 file element names = {mol2_elements_values} \n" - f"QM file element names = {qm_elements_values}" + ValueError, + match=f"ERROR: The QM elements do not match the mol2 file elements, in order. \n" + f"This does not guarantee that the element postions are correct. \n" + f"mol2 file element names = {mol2_elements_values} \n" + f"QM file element names = {qm_elements_values}", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian/CT_CT_C_OH/input/starting_coords/' - 'protonated_fragment_CT_CT_C_OH_in_COOH_bad_element_order.mol2' + "gaussian/CT_CT_C_OH/input/starting_coords/" + "protonated_fragment_CT_CT_C_OH_in_COOH_bad_element_order.mol2" ), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { get_mosdef_dihedral_fit_fn( - 'gaussian/CT_CT_C_OH/output/CT_CT_C_OH_multiplicity_1.log'): [0], + "gaussian/CT_CT_C_OH/output/CT_CT_C_OH_multiplicity_1.log" + ): [0], }, - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3']], + zeroed_dihedral_atom_types=[["CT", "CT", "C", "O_3"]], qm_engine="gaussian", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) - def test_gaussian_style_files_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH_bad_element_order_mol2(self): - mol2_elements_values = "\['C', 'C', 'O', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" - qm_elements_values = "\['C', 'C', 'C', 'O', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" + def test_gaussian_style_files_fit_oplsaa_protonated_fragment_CT_CT_C_OH_in_COOH_bad_element_order_mol2( + self, + ): + mol2_elements_values = ( + "\['C', 'C', 'O', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" + ) + qm_elements_values = ( + "\['C', 'C', 'C', 'O', 'O', 'H', 'H', 'H', 'H', 'H', 'H'\]" + ) with pytest.raises( - ValueError, - match=f"ERROR: The QM elements do not match the mol2 file elements, in order. \n" - f"This does not guarantee that the element postions are correct. \n" - f"mol2 file element names = {mol2_elements_values} \n" - f"QM file element names = {qm_elements_values}" + ValueError, + match=f"ERROR: The QM elements do not match the mol2 file elements, in order. \n" + f"This does not guarantee that the element postions are correct. \n" + f"mol2 file element names = {mol2_elements_values} \n" + f"QM file element names = {qm_elements_values}", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH/input/" + "starting_coords/CT_CT_C_3_OH_bad_element_order.mol2" + ), get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/' - 'starting_coords/CT_CT_C_3_OH_bad_element_order.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH_zeroed.xml'), + "oplsaa_CT_CT_C_OH_in_COOH_zeroed.xml" + ), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH/output'): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH/output" + ): [], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], zeroed_dihedral_atom_types=None, qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=5e-03 + fit_validation_r_squared_rtol=5e-03, ) def test_gaussian_log_file_variable_VDWGeometricSigma_default(self): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=None, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) - with open("GOMC_simulations/GOMC_OPLS_fit_3_dihedral_coords_1.conf", "r") as fp: + with open( + "GOMC_simulations/GOMC_OPLS_fit_3_dihedral_coords_1.conf", "r" + ) as fp: variables_read_dict = { "VDWGeometricSigma": False, } @@ -2834,24 +3367,30 @@ def test_gaussian_log_file_variable_VDWGeometricSigma_default(self): def test_gaussian_log_file_variable_VDWGeometricSigma_True(self): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=None, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) - with open("GOMC_simulations/GOMC_OPLS_fit_3_dihedral_coords_1.conf", "r") as fp: + with open( + "GOMC_simulations/GOMC_OPLS_fit_3_dihedral_coords_1.conf", "r" + ) as fp: variables_read_dict = { "VDWGeometricSigma": False, } @@ -2870,24 +3409,30 @@ def test_gaussian_log_file_variable_VDWGeometricSigma_True(self): def test_gaussian_log_file_variable_VDWGeometricSigma_False(self): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) - with open("GOMC_simulations/GOMC_OPLS_fit_3_dihedral_coords_1.conf", "r") as fp: + with open( + "GOMC_simulations/GOMC_OPLS_fit_3_dihedral_coords_1.conf", "r" + ) as fp: variables_read_dict = { "VDWGeometricSigma": False, } @@ -2906,1173 +3451,1411 @@ def test_gaussian_log_file_variable_VDWGeometricSigma_False(self): def test_bad_fit_dihedral_atom_types_input_list_of_3(self): with pytest.raises( - TypeError, - match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 'CT', 'CT'\], " - r"but it needs to be a list of 4 strings, " - r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\]." + TypeError, + match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 'CT', 'CT'\], " + r"but it needs to be a list of 4 strings, " + r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\].", ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_bad_fit_dihedral_atom_types_input_list_of_4_with_int_at_0(self): with pytest.raises( - TypeError, - match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \[0, 'CT', 'CT', 'HC'\], " - r"but it needs to be a list of 4 strings, " - r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\]." + TypeError, + match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \[0, 'CT', 'CT', 'HC'\], " + r"but it needs to be a list of 4 strings, " + r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\].", ): fit_dihedral_with_gomc( - [0, 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + [0, "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_bad_fit_dihedral_atom_types_input_list_of_4_with_int_at_1(self): with pytest.raises( - TypeError, - match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 1, 'CT', 'HC'\], " - r"but it needs to be a list of 4 strings, " - r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\]." + TypeError, + match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 1, 'CT', 'HC'\], " + r"but it needs to be a list of 4 strings, " + r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\].", ): fit_dihedral_with_gomc( - ['HC', 1, 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", 1, "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_bad_fit_dihedral_atom_types_input_list_of_4_with_int_at_2(self): with pytest.raises( - TypeError, - match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 'CT', 2, 'HC'\], " - r"but it needs to be a list of 4 strings, " - r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\]." + TypeError, + match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 'CT', 2, 'HC'\], " + r"but it needs to be a list of 4 strings, " + r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\].", ): fit_dihedral_with_gomc( - ['HC', 'CT', 2, 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", 2, "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_bad_fit_dihedral_atom_types_input_list_of_4_with_int_at_3(self): with pytest.raises( - TypeError, - match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 'CT', 'CT', 3\], " - r"but it needs to be a list of 4 strings, " - r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\]." + TypeError, + match=r"ERROR: The input 'fit_dihedral_atom_types' variable = \['HC', 'CT', 'CT', 3\], " + r"but it needs to be a list of 4 strings, " + r"where the strings are the atom types/classes. Example: \['HC', 'CT', 'CT', 'HC'\].", ): fit_dihedral_with_gomc( - ['HC','CT', 'CT', 3], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", 3], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_mol2_selection_file_does_not_exist(self): - value_path_mol2='bad_mol2_path.mol2' + value_path_mol2 = "bad_mol2_path.mol2" with pytest.raises( - ValueError, - match=f"ERROR: The {value_path_mol2} file " - r"\('mol2_selection'\) does not exists."): - + ValueError, + match=f"ERROR: The {value_path_mol2} file " + r"\('mol2_selection'\) does not exists.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], + ["HC", "CT", "CT", "HC"], value_path_mol2, - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_mol2_selection_file_no_mol2_extention(self): - value_path_mol2='bad_mol2_path' + value_path_mol2 = "bad_mol2_path" with pytest.raises( - ValueError, - match=r"ERROR: Please enter enter mol2 file \('mol2_selection'\) name with the .mol2 extension."): - + ValueError, + match=r"ERROR: Please enter enter mol2 file \('mol2_selection'\) name with the .mol2 extension.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], + ["HC", "CT", "CT", "HC"], value_path_mol2, - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_mol2_selection_file_not_a_string(self): - value_path_mol2=1 + value_path_mol2 = 1 with pytest.raises( - TypeError, - match=r"ERROR: Please enter mol2 file \('mol2_selection'\) as a string."): - + TypeError, + match=r"ERROR: Please enter mol2 file \('mol2_selection'\) as a string.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], + ["HC", "CT", "CT", "HC"], value_path_mol2, - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_xml_selection_file_does_not_exist(self): - value_path_xml='bad_xml_path.xml' + value_path_xml = "bad_xml_path.xml" with pytest.raises( - ValueError, - match=f"ERROR: The {value_path_xml} file " - r"\('forcefield_selection'\) does not exists."): - + ValueError, + match=f"ERROR: The {value_path_xml} file " + r"\('forcefield_selection'\) does not exists.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), value_path_xml, 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_xml_selection_file_no_xml_extention(self): - value_path_xml='bad_xml_path' + value_path_xml = "bad_xml_path" with pytest.raises( - ValueError, - match=r"ERROR: Please enter enter xml file " - r"\('forcefield_selection'\) name with the .xml extension."): - + ValueError, + match=r"ERROR: Please enter enter xml file " + r"\('forcefield_selection'\) name with the .xml extension.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), value_path_xml, 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_xml_selection_file_not_a_string(self): - value_path_xml=1 + value_path_xml = 1 with pytest.raises( - TypeError, - match=r"ERROR: Please enter xml file \('forcefield_selection'\) as a string."): - + TypeError, + match=r"ERROR: Please enter xml file \('forcefield_selection'\) as a string.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), value_path_xml, 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_temperature_unyt_units_not_a_temperture_but_pressure(self): with pytest.raises( - ValueError, - match=f"ERROR: The 'temperature_unyt_units' is not temperature of type {type(u.unyt_quantity)}."): + ValueError, + match=f"ERROR: The 'temperature_unyt_units' is not temperature of type {type(u.unyt_quantity)}.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.bar, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_temperature_unyt_units_not_in_unyt_units(self): with pytest.raises( - TypeError, - match=f"ERROR: The 'temperature_unyt_units' is not temperature of type {type(u.unyt_quantity)}."): + TypeError, + match=f"ERROR: The 'temperature_unyt_units' is not temperature of type {type(u.unyt_quantity)}.", + ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_not_a_dict(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, - ['x'], + ["x"], zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_key_1_not_a_string(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { 1: [], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): [0,1], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): [0, 1], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_key_2_not_a_string(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [], - 2: [0,1], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [], + 2: [0, 1], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_value_1_not_a_list(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): 's', get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): [0,1], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): "s", + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): [0, 1], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_value_2_not_a_list(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): 'x', + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): "x", }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_list_1_not_all_int(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [0, 's'], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): 'x', + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [0, "s"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): "x", }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_list_2_not_all_int(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): [0, 5, 's'], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): [0, 5, "s"], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_list_1_int_less_than_0(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [-1], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): [0, 5], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [-1], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): [0, 5], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_qm_log_files_and_entries_list_2_int_less_than_0(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " - r"with a string keys and list of int>=0 as the values. Example: " - r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}" + TypeError, + match=r"ERROR: The 'qm_log_files_and_entries_to_remove_dict' is not a dict " + r"with a string keys and list of int>=0 as the values. Example: " + r"\{'path/HC_CT_CT_HC_part_1.log'\): \[\], 'path/HC_CT_CT_HC_part_2.log'\): \[0, 5\]\}", ): - fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [], get_mosdef_dihedral_fit_fn( - 'gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log'): [0, -5], + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1_copy_for_test.log" + ): [0, -5], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_gomc_binary_path_not_a_string(self): with pytest.raises( - TypeError, - match=r"ERROR: Please enter the 'gomc_binary_path' file as a string." + TypeError, + match=r"ERROR: Please enter the 'gomc_binary_path' file as a string.", ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, 99999, { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) - def test_gomc_binary_path_containing_the_GOMC_CPU_NVT_file_does_not_exist(self): + def test_gomc_binary_path_containing_the_GOMC_CPU_NVT_file_does_not_exist( + self, + ): with pytest.raises( - ValueError, - match=r"ERROR: The 'gomc_binary_path' file does not exist or contain the GOMC 'GOMC_CPU_NVT' file." + ValueError, + match=r"ERROR: The 'gomc_binary_path' file does not exist or contain the GOMC 'GOMC_CPU_NVT' file.", ): fit_dihedral_with_gomc( - ['HC', 'CT', 'CT', 'HC'], - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_ethane_HC_CT_CT_HC.xml'), + ["HC", "CT", "CT", "HC"], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/input/starting_coords/ethane_aa.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_ethane_HC_CT_CT_HC.xml"), 298.15 * u.Kelvin, f"gomc_binary_directory", { - get_mosdef_dihedral_fit_fn('gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log'): [], + get_mosdef_dihedral_fit_fn( + "gaussian/HC_CT_CT_HC/output/HC_CT_CT_HC_multiplicity_1.log" + ): [], }, zeroed_dihedral_atom_types=None, qm_engine="gaussian", VDWGeometricSigma=False, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=1e-03 + fit_validation_r_squared_rtol=1e-03, ) def test_zeroed_dihedral_atom_types_not_list(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types='str', + zeroed_dihedral_atom_types="str", qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_zeroed_dihedral_atom_types_list_1_str(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=['str', ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=["str", ["HC", "CT", "CT", "C"]], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_zeroed_dihedral_atom_types_list_2_str(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], 'str'], + zeroed_dihedral_atom_types=[["CT", "CT", "C", "O_3"], "str"], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_zeroed_dihedral_atom_types_list_1_not_4_strings(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 1, 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", 1, "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_zeroed_dihedral_atom_types_list_2_not_4_strings(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 2, 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", 2, "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_zeroed_dihedral_atom_types_list_1_not_lenght_4(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_zeroed_dihedral_atom_types_list_2_not_lenght_4(self): with pytest.raises( - TypeError, - match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " - r"lists with 4 strings each. Example: " - r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\]." + TypeError, + match=r"ERROR: The 'zeroed_dihedral_atom_types' is not None or a list containing " + r"lists with 4 strings each. Example: " + r"\[\['CT', 'CT, 'CT, 'HC'\], \['NT', 'CT, 'CT, 'HC'\]\].", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_qm_engine_not_correct_value(self): with pytest.raises( - ValueError, - match=f"ERROR: The 'qm_engine' = {'x'}, which is not " - f"any of the available options. " - f"The options are 'gaussian' or 'gaussian_style_final_files'." + ValueError, + match=f"ERROR: The 'qm_engine' = {'x'}, which is not " + f"any of the available options. " + f"The options are 'gaussian' or 'gaussian_style_final_files'.", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="x", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_qm_engine_not_a_string(self): with pytest.raises( - TypeError, - match=f"ERROR: The 'qm_engine' is a {type(['x'])}, but it needs to be a str." + TypeError, + match=f"ERROR: The 'qm_engine' is a {type(['x'])}, but it needs to be a str.", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine=["x"], VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_atom_type_naming_style_not_correct_value(self): with pytest.raises( - ValueError, - match=f"ERROR: The 'atom_type_naming_style' = {'x'}, which is not " - f"any of the available options. " - f"The options are 'general' or 'all_unique'." + ValueError, + match=f"ERROR: The 'atom_type_naming_style' = {'x'}, which is not " + f"any of the available options. " + f"The options are 'general' or 'all_unique'.", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='x', + atom_type_naming_style="x", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_atom_type_naming_style_not_a_string(self): with pytest.raises( - TypeError, - match=f"ERROR: The 'atom_type_naming_style' is a {type(['x'])}, but it needs to be a str." + TypeError, + match=f"ERROR: The 'atom_type_naming_style' is a {type(['x'])}, but it needs to be a str.", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, atom_type_naming_style=["x"], gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_gomc_cpu_cores_not_correct_value(self): with pytest.raises( - ValueError, - match=f"ERROR: The 'gomc_cpu_cores' = {0}, and it must be an int > 0." + ValueError, + match=f"ERROR: The 'gomc_cpu_cores' = {0}, and it must be an int > 0.", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=0, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_gomc_cpu_cores_not_a_int(self): with pytest.raises( - TypeError, - match=f"ERROR: The 'gomc_cpu_cores' is a {type(1.000)}, but it needs to be a int." + TypeError, + match=f"ERROR: The 'gomc_cpu_cores' is a {type(1.000)}, but it needs to be a int.", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3'], ['HC', 'CT', 'CT', 'C']], + zeroed_dihedral_atom_types=[ + ["CT", "CT", "C", "O_3"], + ["HC", "CT", "CT", "C"], + ], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1.000, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.02 + fit_validation_r_squared_rtol=0.02, ) def test_fit_min_validated_r_squared_not_correct_value_is_0(self): with pytest.raises( - ValueError, - match=f"ERROR: The 'fit_min_validated_r_squared'= {0.00}, " - f"but it must be a 0= " \ - f"{'0.99'}, " - f"within the relative tolerance or 'fit_validation_r_squared_rtol' = " - f"{'2e-07'}. \n" - f"- Fit via the individual or multi-dihedral fit, when " - f"Gaussian minus GOMC with the selected dihedral set to zero \n" - f"--> R-squared = " - f"{'0.99792638'} \n" - f"- Fit via the validation test case, when " - f"Gaussian minus GOMC with the selected individual dihedral added in GOMC \n" - f"-- >R-squared = " - f"{'0.98698695'} \n" - f"The 'fit_min_validated_r_squared' and 'fit_validation_r_squared_rtol' " - f"variables may need to be adjusted, \n" - f"there is likely something wrong with the fitting procedure, the " - f"software parameters need tuned, or there is a bug in the software. \n\n " - f"NOTE: Since the R-squared values are calculated via different parameters, \n" - f"the compared R-squared values could be very different if they are not nearly \n" - r"a perfect fit \(R-squared --> ~0.98 to 0.99999999\)." + ValueError, + match=f"ERROR: The calculated R-squared energy values from the fit type " + f"{'1_2_3'} " + f"does not match the validated case for 'fit_min_validated_r_squared' >= " + f"{'0.99'}, " + f"within the relative tolerance or 'fit_validation_r_squared_rtol' = " + f"{'2e-07'}. \n" + f"- Fit via the individual or multi-dihedral fit, when " + f"Gaussian minus GOMC with the selected dihedral set to zero \n" + f"--> R-squared = " + f"{'0.99792638'} \n" + f"- Fit via the validation test case, when " + f"Gaussian minus GOMC with the selected individual dihedral added in GOMC \n" + f"-- >R-squared = " + f"{'0.98698695'} \n" + f"The 'fit_min_validated_r_squared' and 'fit_validation_r_squared_rtol' " + f"variables may need to be adjusted, \n" + f"there is likely something wrong with the fitting procedure, the " + f"software parameters need tuned, or there is a bug in the software. \n\n " + f"NOTE: Since the R-squared values are calculated via different parameters, \n" + f"the compared R-squared values could be very different if they are not nearly \n" + r"a perfect fit \(R-squared --> ~0.98 to 0.99999999\).", ): fit_dihedral_with_gomc( - ['CT', 'CT', 'C', 'OH'], + ["CT", "CT", "C", "OH"], get_mosdef_dihedral_fit_fn( - 'gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2'), - get_mosdef_dihedral_fit_fn('oplsaa_CT_CT_C_OH_in_COOH.xml'), + "gaussian_style_output_files/CT_CT_C_OH/input/starting_coords/CT_CT_C_3_OH.mol2" + ), + get_mosdef_dihedral_fit_fn("oplsaa_CT_CT_C_OH_in_COOH.xml"), 298.15 * u.Kelvin, gomc_binary_directory, { - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_2/output'): [], - get_mosdef_dihedral_fit_fn('gaussian_style_output_files/CT_CT_C_OH_split_part_1/output'): [0], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_2/output" + ): [], + get_mosdef_dihedral_fit_fn( + "gaussian_style_output_files/CT_CT_C_OH_split_part_1/output" + ): [0], }, manual_dihedral_atom_numbers_list=[3, 2, 1, 4], - zeroed_dihedral_atom_types=[['CT', 'CT', 'C', 'O_3']], + zeroed_dihedral_atom_types=[["CT", "CT", "C", "O_3"]], qm_engine="gaussian_style_final_files", VDWGeometricSigma=True, - atom_type_naming_style='general', + atom_type_naming_style="general", gomc_cpu_cores=1, fit_min_validated_r_squared=0.99, - fit_validation_r_squared_rtol=0.0000002 - ) \ No newline at end of file + fit_validation_r_squared_rtol=0.0000002, + ) diff --git a/mosdef_dihedral_fit/tests/test_math_operation.py b/mosdef_dihedral_fit/tests/test_math_operation.py index 0d5d886..26180bf 100644 --- a/mosdef_dihedral_fit/tests/test_math_operation.py +++ b/mosdef_dihedral_fit/tests/test_math_operation.py @@ -1,8 +1,9 @@ -import pytest import numpy as np +import pytest + +import mosdef_dihedral_fit.utils.math_operations as mdf_math from mosdef_dihedral_fit.tests.base_test import BaseTest from mosdef_dihedral_fit.utils.io import get_mosdef_dihedral_fit_fn -import mosdef_dihedral_fit.utils.math_operations as mdf_math class TestMathOperations(BaseTest): @@ -12,22 +13,25 @@ class TestMathOperations(BaseTest): def test_round_to_sig_figs(self): test_sigfig_input_value = 122.283638245 - expected_values = [0.0, - 100.0, - 120.0, - 122.0, - 122.3, - 122.28, - 122.284, - 122.2836, - 122.28364, - 122.283638, - 122.2836382, - 122.28363825, - 122.283638245] + expected_values = [ + 0.0, + 100.0, + 120.0, + 122.0, + 122.3, + 122.28, + 122.284, + 122.2836, + 122.28364, + 122.283638, + 122.2836382, + 122.28363825, + 122.283638245, + ] for i in range(len(expected_values)): test_return_value = mdf_math.round_to_sig_figs( - test_sigfig_input_value, sig_figs=i) + test_sigfig_input_value, sig_figs=i + ) assert test_return_value == expected_values[i] def test_round_to_3_default_sig_figs(self): @@ -77,14 +81,15 @@ def test_normalize_vectors(self): def test_normalize_vector_error(self): with pytest.raises( - ValueError, - match=f"ERROR: The normal vector = 0, indicating that these lines or planes " - f"lay on top each other or are perpendicular. \n" - f"The input vector = \[0 0 0\]", + ValueError, + match=f"ERROR: The normal vector = 0, indicating that these lines or planes " + f"lay on top each other or are perpendicular. \n" + f"The input vector = \[0 0 0\]", ): test_vector_input_value = [0, 0, 0] test_return_value = mdf_math.normalize_vector( - test_vector_input_value) + test_vector_input_value + ) # ******************************************** # test the normalize_vector (END) @@ -99,8 +104,7 @@ def test_angle_between_2_vectors(self): test_vector_1_input_value = np.array([1.2, -2.3, 3.4]) test_vector_2_input_value = np.array([2.1, -4.3, 6.4]) test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) assert isinstance(test_return_value, float) @@ -110,8 +114,7 @@ def test_angle_between_2_vectors(self): test_vector_1_input_value = np.array([1, 0, 0]) test_vector_2_input_value = np.array([0, 1, 0]) test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) assert isinstance(test_return_value, float) @@ -121,8 +124,7 @@ def test_angle_between_2_vectors(self): test_vector_1_input_value = [1, 0, 0] test_vector_2_input_value = [0, 0, 1] test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) assert isinstance(test_return_value, float) @@ -132,8 +134,7 @@ def test_angle_between_2_vectors(self): test_vector_1_input_value = [1, 0, 0] test_vector_2_input_value = [1, 1, 1] test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) assert isinstance(test_return_value, float) @@ -143,8 +144,7 @@ def test_angle_between_2_vectors(self): test_vector_1_input_value = [0.999999999999999, 0, 0] test_vector_2_input_value = [-1, 0, 0] test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) assert isinstance(test_return_value, float) @@ -154,8 +154,7 @@ def test_angle_between_2_vectors(self): test_vector_1_input_value = [0, 0.999999999999999, 0] test_vector_2_input_value = [0, 1, 0] test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) assert isinstance(test_return_value, float) @@ -164,30 +163,28 @@ def test_angle_between_2_vectors(self): def test_angle_between_2_vectors_errors(self): # Error 1 with pytest.raises( - ValueError, - match=f"ERROR: The 'vector_1' or 'vector_2', and |vector_1||vector_2| == 0, which means the \n" - f"angle can not be calculated due to the divisor being zero in the formula; \n" - f"angle = arccos\[\(vector_1 dot vector_2\)/\(|vector_1||vector_2|\)\]", + ValueError, + match=f"ERROR: The 'vector_1' or 'vector_2', and |vector_1||vector_2| == 0, which means the \n" + f"angle can not be calculated due to the divisor being zero in the formula; \n" + f"angle = arccos\[\(vector_1 dot vector_2\)/\(|vector_1||vector_2|\)\]", ): test_vector_1_input_value = [0, 0, 0] test_vector_2_input_value = [1, 1, 1] test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) # Error 2 with pytest.raises( - ValueError, - match=f"ERROR: The 'vector_1' or 'vector_2', and |vector_1||vector_2| == 0, which means the \n" - f"angle can not be calculated due to the divisor being zero in the formula; \n" - f"angle = arccos\[\(vector_1 dot vector_2\)/\(|vector_1||vector_2|\)\]", + ValueError, + match=f"ERROR: The 'vector_1' or 'vector_2', and |vector_1||vector_2| == 0, which means the \n" + f"angle can not be calculated due to the divisor being zero in the formula; \n" + f"angle = arccos\[\(vector_1 dot vector_2\)/\(|vector_1||vector_2|\)\]", ): test_vector_1_input_value = [1, 1, 1] test_vector_2_input_value = [0, 0, 0] test_return_value = mdf_math.angle_between_2_vectors( - test_vector_1_input_value, - test_vector_2_input_value + test_vector_1_input_value, test_vector_2_input_value ) # ******************************************** @@ -203,13 +200,13 @@ def test_dihedral_angle(self): [-1.157250, 0.086030, 1.008021], [-0.763996, -0.002151, 0.000087], [0.763996, -0.002151, -0.000087], - [1.157250, 0.086030, -1.008021] + [1.157250, 0.086030, -1.008021], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -220,13 +217,13 @@ def test_dihedral_angle(self): [0.087884, 1.169649, -1.004308], [0.000000, 0.770018, 0.000246], [0.000000, -0.770018, 0.000246], - [-0.087884, -1.169649, -1.004308] + [-0.087884, -1.169649, -1.004308], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -237,13 +234,13 @@ def test_dihedral_angle(self): [-0.000003, 1.170693, -1.00809], [0.000000, 0.770615, 0.000082], [0.000000, -0.770615, 0.000082], - [0.000003, -1.170693, -1.008099] + [0.000003, -1.170693, -1.008099], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -254,13 +251,13 @@ def test_dihedral_angle(self): [-0.087902, 1.169402, -1.004392], [-0.000000, 0.770059, 0.000295], [0.000000, -0.770059, 0.000295], - [0.087902, -1.169402, -1.004392] + [0.087902, -1.169402, -1.004392], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -271,13 +268,13 @@ def test_dihedral_angle(self): [-0.995768, 1.159585, -0.172100], [0.000000, 0.765133, 0.003478], [-0.000000, -0.765133, 0.003478], - [0.995768, -1.159585, -0.172100] + [0.995768, -1.159585, -0.172100], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -288,13 +285,13 @@ def test_dihedral_angle(self): [-1.008027, 1.157050, -0.086196], [-0.000000, 0.764044, 0.001992], [-0.000000, -0.764044, 0.001992], - [1.008027, -1.157050, -0.086196] + [1.008027, -1.157050, -0.086196], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -305,13 +302,13 @@ def test_dihedral_angle(self): [-1.012181, 1.156071, -0.000004], [-0.000000, 0.763665, -0.000006], [-0.000000, -0.763665, -0.000006], - [1.012181, -1.156071, -0.000004] + [1.012181, -1.156071, -0.000004], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) assert isinstance(test_return_value, float) @@ -320,142 +317,143 @@ def test_dihedral_angle(self): def test_dihedral_angle_error_1(self): # Test case 1 with pytest.raises( - ValueError, - match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" - f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" - f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_2 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" - f"atom_xyz_coord_4 = \[10, 11, 12\]. " + ValueError, + match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" + f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" + f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_2 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" + f"atom_xyz_coord_4 = \[10, 11, 12\]. ", ): test_vectors_input_value = [ [1, 2, 3], [1, 2, 3], [7, 8, 9], - [10, 11, 12] + [10, 11, 12], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) # Test case 2 with pytest.raises( - ValueError, - match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" - f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" - f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" - f"atom_xyz_coord_3 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_4 = \[10, 11, 12\]. " + ValueError, + match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" + f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" + f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" + f"atom_xyz_coord_3 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_4 = \[10, 11, 12\]. ", ): test_vectors_input_value = [ [1, 2, 3], [4, 5, 6], [1, 2, 3], - [10, 11, 12] + [10, 11, 12], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) # Test case 3 with pytest.raises( - ValueError, - match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" - f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" - f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" - f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" - f"atom_xyz_coord_4 = \[1, 2, 3\]. " + ValueError, + match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" + f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" + f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" + f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" + f"atom_xyz_coord_4 = \[1, 2, 3\]. ", ): test_vectors_input_value = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], - [1, 2, 3] + [1, 2, 3], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) def test_dihedral_angle_error_2(self): # Test case 1 with pytest.raises( - ValueError, - match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" - f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" - f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" - f"atom_xyz_coord_3 = \[4, 5, 6\]; \n" - f"atom_xyz_coord_4 = \[10, 11, 12\]. " + ValueError, + match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" + f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" + f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" + f"atom_xyz_coord_3 = \[4, 5, 6\]; \n" + f"atom_xyz_coord_4 = \[10, 11, 12\]. ", ): test_vectors_input_value = [ [1, 2, 3], [4, 5, 6], [4, 5, 6], - [10, 11, 12] + [10, 11, 12], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) # Test case 2 with pytest.raises( - ValueError, - match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" - f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" - f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" - f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" - f"atom_xyz_coord_4 = \[4, 5, 6\]. " + ValueError, + match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" + f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" + f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" + f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" + f"atom_xyz_coord_4 = \[4, 5, 6\]. ", ): test_vectors_input_value = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], - [4, 5, 6] + [4, 5, 6], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) def test_dihedral_angle_error_3(self): with pytest.raises( - ValueError, - match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" - f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" - f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" - f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" - f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" - f"atom_xyz_coord_4 = \[7, 8, 9\]. " + ValueError, + match=f"ERROR: The one or more of the atom coordinates are the same when entered into \n" + f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" + f"atom_xyz_coord_1 = \[1, 2, 3\]; \n" + f"atom_xyz_coord_2 = \[4, 5, 6\]; \n" + f"atom_xyz_coord_3 = \[7, 8, 9\]; \n" + f"atom_xyz_coord_4 = \[7, 8, 9\]. ", ): test_vectors_input_value = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], - [7, 8, 9] + [7, 8, 9], ] test_return_value = mdf_math.dihedral_angle( test_vectors_input_value[0], test_vectors_input_value[1], test_vectors_input_value[2], - test_vectors_input_value[3] + test_vectors_input_value[3], ) + # ******************************************** # test the dihedral_angle (END) # ******************************************** diff --git a/mosdef_dihedral_fit/utils/file_read_and_write.py b/mosdef_dihedral_fit/utils/file_read_and_write.py index 7022fa2..aef9b9a 100755 --- a/mosdef_dihedral_fit/utils/file_read_and_write.py +++ b/mosdef_dihedral_fit/utils/file_read_and_write.py @@ -1,15 +1,15 @@ import os import shutil import subprocess +import warnings +from warnings import warn + import numpy as np -import mosdef_dihedral_fit.utils.math_operations as mdf_math import vmd - -from scipy.optimize import curve_fit from mosdef_gomc.utils.conversion import OPLS_to_periodic +from scipy.optimize import curve_fit -import warnings -from warnings import warn +import mosdef_dihedral_fit.utils.math_operations as mdf_math def get_atom_names_and_elements_from_mol2(mol2_directory_and_filename): @@ -38,14 +38,18 @@ def get_atom_names_and_elements_from_mol2(mol2_directory_and_filename): for m, line_m in enumerate(readlines_mol2_file): split_line_m = line_m.split() - if (len(split_line_m) > 0 and str(split_line_m[0]) in ["@BOND"]): + if len(split_line_m) > 0 and str(split_line_m[0]) in [ + "@BOND" + ]: get_atom_type_bool = False if len(split_line_m) in [8, 9] and get_atom_type_bool is True: atom_name_list.append(split_line_m[1]) element_name_list.append(split_line_m[5]) - if len(split_line_m) > 0 and str(split_line_m[0]) in ["@ATOM"]: + if len(split_line_m) > 0 and str(split_line_m[0]) in [ + "@ATOM" + ]: get_atom_type_bool = True if len(atom_name_list) == 0 or len(element_name_list) == 0: @@ -91,19 +95,17 @@ def get_atom_names_and_elements_from_pdb(pdb_directory_and_filename): get_atom_type_bool = False # and len(split_line_m) in [10, 11, 12] - if split_line_m[0] in ['ATOM'] and get_atom_type_bool is True: - atom_name_j = '' - element_name_j = '' + if split_line_m[0] in ["ATOM"] and get_atom_type_bool is True: + atom_name_j = "" + element_name_j = "" for fix_space_j in range(12, 12 + len(line_m[12:16])): - atom_name_str_space_iter = line_m[fix_space_j] - if atom_name_str_space_iter != ' ': + if atom_name_str_space_iter != " ": atom_name_j += atom_name_str_space_iter for fix_space_k in range(76, 76 + len(line_m[76:79])): - element_name_str_space_iter = line_m[fix_space_k] - if element_name_str_space_iter != ' ': + if element_name_str_space_iter != " ": element_name_j += element_name_str_space_iter atom_name_list.append(atom_name_j) @@ -121,12 +123,13 @@ def get_atom_names_and_elements_from_pdb(pdb_directory_and_filename): return [atom_name_list, element_name_list] -def write_xyz_file_from_gaussian_coordinates(atom_names_list, - qm_parital_coordinate_file_starting_dir_and_name, - qm_coordinate_file_extension, - xyz_files_directory, - total_qm_scans - ): +def write_xyz_file_from_gaussian_coordinates( + atom_names_list, + qm_parital_coordinate_file_starting_dir_and_name, + qm_coordinate_file_extension, + xyz_files_directory, + total_qm_scans, +): """Write the xyz files from the extracted Gaussian coordinate file. This write the xyz files from the extracted Gaussian coordinate file. @@ -160,7 +163,10 @@ def write_xyz_file_from_gaussian_coordinates(atom_names_list, with the file name 'dihedral_coords_position_n.xyz'. """ # check if file extension starts with a "." or not remove for correct insertion later - if len(qm_coordinate_file_extension) > 0 and qm_coordinate_file_extension[0] == ".": + if ( + len(qm_coordinate_file_extension) > 0 + and qm_coordinate_file_extension[0] == "." + ): qm_coordinate_file_extension = qm_coordinate_file_extension[1:] elif len(qm_coordinate_file_extension) > 0: @@ -174,18 +180,19 @@ def write_xyz_file_from_gaussian_coordinates(atom_names_list, # add 1 spaces infront of atom_names_list atom_names_with_2_spaces_in_front = [] for j_iter in range(0, len(atom_names_list)): - atom_names_with_2_spaces_in_front.append( - f" {atom_names_list[j_iter]}") + atom_names_with_2_spaces_in_front.append(f" {atom_names_list[j_iter]}") for i_iter in range(1, total_qm_scans + 1): - read_gausian_file_dir_name = \ - f'{qm_parital_coordinate_file_starting_dir_and_name}{i_iter}.{qm_coordinate_file_extension}' + read_gausian_file_dir_name = f"{qm_parital_coordinate_file_starting_dir_and_name}{i_iter}.{qm_coordinate_file_extension}" - new_file_name_each_point = \ - f'{xyz_files_directory}/dihedral_coords_position_{i_iter}.xyz' + new_file_name_each_point = ( + f"{xyz_files_directory}/dihedral_coords_position_{i_iter}.xyz" + ) number_of_atoms = str(int(len(atom_names_with_2_spaces_in_front))) - comment_1_space_in_front = f" generated by Python script from Gaussian data" + comment_1_space_in_front = ( + f" generated by Python script from Gaussian data" + ) output_file_xyz_file = open(new_file_name_each_point, "w") output_file_xyz_file.write(f"{number_of_atoms}\n") @@ -193,11 +200,14 @@ def write_xyz_file_from_gaussian_coordinates(atom_names_list, # The Gaussian file need to have these columns "Row Highlight Display Tag Symbol X Y Z" check_guassian_optimized_coordinate_file_correct( - read_gausian_file_dir_name) + read_gausian_file_dir_name + ) with open(read_gausian_file_dir_name, "r") as fp: readlines_gausian_file = fp.readlines() for i, line in enumerate(readlines_gausian_file): - if i == 0 and not ("Row Highlight Display Tag Symbol X Y Z" in line): + if i == 0 and not ( + "Row Highlight Display Tag Symbol X Y Z" in line + ): raise ValueError( "# The Gaussian file need to have these columns " "'Row Highlight Display Tag Symbol X Y Z'" @@ -209,7 +219,6 @@ def write_xyz_file_from_gaussian_coordinates(atom_names_list, f"{readlines_gausian_file[i].split()[5]: <20}\t" f"{readlines_gausian_file[i].split()[6]: <20}\t" f"{readlines_gausian_file[i].split()[7]: <20}\n" - ) output_file_xyz_file.close() @@ -243,7 +252,8 @@ def write_restart_coor_from_xyz_file(coor_files_directory, total_qm_scans): # ******************************************* write_coor_vmd_source_file = f"write_restart_files.tcl" output_file_restart_coor = open( - f"{coor_files_directory}/{write_coor_vmd_source_file}", "w") + f"{coor_files_directory}/{write_coor_vmd_source_file}", "w" + ) output_file_restart_coor.write(f"package require topotools\n\n") output_file_restart_coor.write(f"set NumberPositions {total_qm_scans}\n") @@ -253,13 +263,14 @@ def write_restart_coor_from_xyz_file(coor_files_directory, total_qm_scans): output_file_restart_coor.write(f'set xyzExtension ".xyz"\n') output_file_restart_coor.write(f'set NAMDbinExtension ".coor"\n\n') - output_file_restart_coor.write("for {set x 1} {$x <= $NumberPositions} {incr x} {\n" - "\tset xyzFilename $xyzAndCoorDirectoryBaseFilename$x$xyzExtension\n" - "\ttopo readvarxyz $xyzFilename\n\n" - "\tset NAMDBinFilename $xyzAndCoorDirectoryBaseFilename$x$NAMDbinExtension\n" - "\tanimate write namdbin $NAMDBinFilename\n\n" - "}\n\n" - ) + output_file_restart_coor.write( + "for {set x 1} {$x <= $NumberPositions} {incr x} {\n" + "\tset xyzFilename $xyzAndCoorDirectoryBaseFilename$x$xyzExtension\n" + "\ttopo readvarxyz $xyzFilename\n\n" + "\tset NAMDBinFilename $xyzAndCoorDirectoryBaseFilename$x$NAMDbinExtension\n" + "\tanimate write namdbin $NAMDBinFilename\n\n" + "}\n\n" + ) output_file_restart_coor.close() # ******************************************* @@ -272,9 +283,9 @@ def write_restart_coor_from_xyz_file(coor_files_directory, total_qm_scans): # (START) # ******************************************* - os.chdir(f'{coor_files_directory}') - vmd.evaltcl(f'source {write_coor_vmd_source_file}') - os.chdir(f'..') + os.chdir(f"{coor_files_directory}") + vmd.evaltcl(f"source {write_coor_vmd_source_file}") + os.chdir(f"..") # ******************************************* # change to the 'coor_files_directory' directory and write the .coor restart files via VMD @@ -307,38 +318,51 @@ def check_guassian_angle_energy_file_correct(guassian_energy_file_dir_and_name): """ with open(guassian_energy_file_dir_and_name, "r") as fp: gaussian_dihedral_header_line_correct_bool_list = [ - False, False, False, False, False] + False, + False, + False, + False, + False, + ] gaussian_dihedral_header_file = fp.readlines() for m, line_m in enumerate(gaussian_dihedral_header_file): split_line_m = line_m.split() if m == 0 and len(split_line_m) == 5: - if split_line_m[0] == '#' \ - and split_line_m[1] == 'Scan' \ - and split_line_m[2] == 'of' \ - and split_line_m[3] == 'Total' \ - and split_line_m[4] == 'Energy': + if ( + split_line_m[0] == "#" + and split_line_m[1] == "Scan" + and split_line_m[2] == "of" + and split_line_m[3] == "Total" + and split_line_m[4] == "Energy" + ): gaussian_dihedral_header_line_correct_bool_list[0] = True if m == 1 and len(split_line_m) == 4: - if split_line_m[0] == '#' \ - and split_line_m[1] == 'X-Axis:' \ - and split_line_m[2] == 'Scan' \ - and split_line_m[3] == 'Coordinate': + if ( + split_line_m[0] == "#" + and split_line_m[1] == "X-Axis:" + and split_line_m[2] == "Scan" + and split_line_m[3] == "Coordinate" + ): gaussian_dihedral_header_line_correct_bool_list[1] = True if m == 2 and len(split_line_m) == 5: - if split_line_m[0] == '#' \ - and split_line_m[1] == 'Y-Axis:' \ - and split_line_m[2] == 'Total' \ - and split_line_m[3] == 'Energy' \ - and split_line_m[4] == '(Hartree)': + if ( + split_line_m[0] == "#" + and split_line_m[1] == "Y-Axis:" + and split_line_m[2] == "Total" + and split_line_m[3] == "Energy" + and split_line_m[4] == "(Hartree)" + ): gaussian_dihedral_header_line_correct_bool_list[2] = True if m == 3 and len(split_line_m) == 3: - if split_line_m[0] == '#' \ - and split_line_m[1] == 'X' \ - and split_line_m[2] == 'Y': + if ( + split_line_m[0] == "#" + and split_line_m[1] == "X" + and split_line_m[2] == "Y" + ): gaussian_dihedral_header_line_correct_bool_list[3] = True # this is the 1st data line and should look like '0.0000000000 -266.8384100090' @@ -362,7 +386,9 @@ def check_guassian_angle_energy_file_correct(guassian_energy_file_dir_and_name): return gaussian_angle_energy_file_correct -def check_guassian_optimized_coordinate_file_correct(gaussian_optimized_coordinate_path_and_name): +def check_guassian_optimized_coordinate_file_correct( + gaussian_optimized_coordinate_path_and_name, +): """Check that the Guassian/Gausview file containing the optimized coordinates is formatted correctly. This checks the Guassian/Gausview containing the optimized coordinates is formatted correctly. @@ -389,15 +415,19 @@ def check_guassian_optimized_coordinate_file_correct(gaussian_optimized_coordina split_line_m = line_m.split() if m == 0 and len(split_line_m) == 8: - if split_line_m[0] == 'Row' \ - and split_line_m[1] == 'Highlight' \ - and split_line_m[2] == 'Display' \ - and split_line_m[3] == 'Tag' \ - and split_line_m[4] == 'Symbol'\ - and split_line_m[5] == 'X' \ - and split_line_m[6] == 'Y' \ - and split_line_m[7] == 'Z': - gaussian_optimized_coordinate_header_line_correct_bool = True + if ( + split_line_m[0] == "Row" + and split_line_m[1] == "Highlight" + and split_line_m[2] == "Display" + and split_line_m[3] == "Tag" + and split_line_m[4] == "Symbol" + and split_line_m[5] == "X" + and split_line_m[6] == "Y" + and split_line_m[7] == "Z" + ): + gaussian_optimized_coordinate_header_line_correct_bool = ( + True + ) if gaussian_optimized_coordinate_header_line_correct_bool is False: raise TypeError( @@ -410,8 +440,7 @@ def check_guassian_optimized_coordinate_file_correct(gaussian_optimized_coordina def get_final_gaussian_output_file_data( - qm_log_files_and_entries_to_remove_dict, - manual_dihedral_atom_numbers_list + qm_log_files_and_entries_to_remove_dict, manual_dihedral_atom_numbers_list ): """Get the Guassian/Gausview file data from the existing Guassian/Gausview files. @@ -505,14 +534,23 @@ def get_final_gaussian_output_file_data( f"'{value_j}' is a {type(value_j)} not a list." ) - if not isinstance(manual_dihedral_atom_numbers_list, list) or len(manual_dihedral_atom_numbers_list) != 4: - raise TypeError("ERROR: The 'manual_dihedral_atom_numbers_list' is not a list of length 4.") + if ( + not isinstance(manual_dihedral_atom_numbers_list, list) + or len(manual_dihedral_atom_numbers_list) != 4 + ): + raise TypeError( + "ERROR: The 'manual_dihedral_atom_numbers_list' is not a list of length 4." + ) - elif isinstance(manual_dihedral_atom_numbers_list, list) and len(manual_dihedral_atom_numbers_list) == 4: + elif ( + isinstance(manual_dihedral_atom_numbers_list, list) + and len(manual_dihedral_atom_numbers_list) == 4 + ): for x_i in manual_dihedral_atom_numbers_list: if not isinstance(x_i, int): - raise TypeError("ERROR: The 'manual_dihedral_atom_numbers_list' values are not integers.") - + raise TypeError( + "ERROR: The 'manual_dihedral_atom_numbers_list' values are not integers." + ) all_coordinates_ang_list = [] all_energy_hartree_list = [] @@ -523,31 +561,47 @@ def get_final_gaussian_output_file_data( all_element_names_list = [] dihedral_counter = 0 # start at 1 and add a +1 initially - for direct_gaussian_folder_iter, entries_to_remove_list_iter in qm_log_files_and_entries_to_remove_dict.items(): + for ( + direct_gaussian_folder_iter, + entries_to_remove_list_iter, + ) in qm_log_files_and_entries_to_remove_dict.items(): # reset the dihedral used per file all_used_and_unused_dihedral_angle_degrees_list = [] # run each log file # check the file is correctly formated - direct_gaussian_angles_energy_formated_file_name_iter = f"{direct_gaussian_folder_iter}/dihedral.txt" - check_guassian_angle_energy_file_correct(direct_gaussian_angles_energy_formated_file_name_iter) + direct_gaussian_angles_energy_formated_file_name_iter = ( + f"{direct_gaussian_folder_iter}/dihedral.txt" + ) + check_guassian_angle_energy_file_correct( + direct_gaussian_angles_energy_formated_file_name_iter + ) - with open(direct_gaussian_angles_energy_formated_file_name_iter, "r") as fp1: + with open( + direct_gaussian_angles_energy_formated_file_name_iter, "r" + ) as fp1: first_enerery_dihedral_file_data_header_lines = 4 first_coord_file_data_header_lines = 1 # get the 1st QM Guassian/Gausview file angles and dihedrals direct_gaussian_angles_energy_iter = fp1.readlines() for m, line_m in enumerate(direct_gaussian_angles_energy_iter): - m_less_spacers = int(m - first_enerery_dihedral_file_data_header_lines - 0) + m_less_spacers = int( + m - first_enerery_dihedral_file_data_header_lines - 0 + ) split_line_m = line_m.split() # get all used and unused dihedrals for later pulling coordinates in order if m_less_spacers >= 0 and len(split_line_m) == 2: - all_used_and_unused_dihedral_angle_degrees_list.append(split_line_m[0]) + all_used_and_unused_dihedral_angle_degrees_list.append( + split_line_m[0] + ) - if m_less_spacers >= 0 and len(split_line_m) == 2 \ - and m_less_spacers not in entries_to_remove_list_iter: + if ( + m_less_spacers >= 0 + and len(split_line_m) == 2 + and m_less_spacers not in entries_to_remove_list_iter + ): all_dihedral_angle_degrees_list.append(split_line_m[0]) all_energy_hartree_list.append(split_line_m[1]) @@ -557,36 +611,52 @@ def get_final_gaussian_output_file_data( f"is not in the correct Guassian sytle format." ) - total_used_and_unused_dihedrals_per_file = [len(all_used_and_unused_dihedral_angle_degrees_list)] + total_used_and_unused_dihedrals_per_file = [ + len(all_used_and_unused_dihedral_angle_degrees_list) + ] # iterate through the coord files (added +1 as file names start with 1) - for dih_per_file_i in range(1, total_used_and_unused_dihedrals_per_file[-1] + 1): - + for dih_per_file_i in range( + 1, total_used_and_unused_dihedrals_per_file[-1] + 1 + ): direct_coordinates_ang_list_iter = [] direct_number_of_atoms_list_iter = [] direct_element_names_list_iter = [] direct_dihedral_atom_numbers_list_iter = [] if int(dih_per_file_i - 1) not in entries_to_remove_list_iter: dihedral_counter += 1 - direct_gaussian_coord_formated_file_name_iter = \ - f"{direct_gaussian_folder_iter}/dihedral_coords_position_{dih_per_file_i}.txt" - check_guassian_optimized_coordinate_file_correct(direct_gaussian_coord_formated_file_name_iter) - - with open(direct_gaussian_coord_formated_file_name_iter, "r") as fp2: + direct_gaussian_coord_formated_file_name_iter = f"{direct_gaussian_folder_iter}/dihedral_coords_position_{dih_per_file_i}.txt" + check_guassian_optimized_coordinate_file_correct( + direct_gaussian_coord_formated_file_name_iter + ) + with open( + direct_gaussian_coord_formated_file_name_iter, "r" + ) as fp2: # get the 1st QM Guassian/Gausview file angles and dihedrals direct_gaussian_coord_iter = fp2.readlines() for n, line_n in enumerate(direct_gaussian_coord_iter): split_line_n = line_n.split() - n_less_spacers = int(n - first_coord_file_data_header_lines - 0) + n_less_spacers = int( + n - first_coord_file_data_header_lines - 0 + ) if n_less_spacers >= 0 and len(split_line_n) == 8: - direct_coordinates_ang_list_iter.append( - [float(split_line_n[5]), float(split_line_n[6]), float(split_line_n[7])] + [ + float(split_line_n[5]), + float(split_line_n[6]), + float(split_line_n[7]), + ] + ) + direct_number_of_atoms_list_iter.append( + float(split_line_n[3]) + ) + direct_element_names_list_iter.append( + split_line_n[4] + ) + direct_dihedral_atom_numbers_list_iter.append( + manual_dihedral_atom_numbers_list ) - direct_number_of_atoms_list_iter.append(float(split_line_n[3])) - direct_element_names_list_iter.append(split_line_n[4]) - direct_dihedral_atom_numbers_list_iter.append(manual_dihedral_atom_numbers_list) elif n_less_spacers >= 0 and len(split_line_n) != 8: raise ValueError( @@ -594,44 +664,55 @@ def get_final_gaussian_output_file_data( f"is not in the correct Guassian sytle format" ) - #check the values against the past ones - if len(all_coordinates_ang_list) == 0 \ - and len(all_number_of_atoms_list) == 0 \ - and len(all_element_names_list) == 0: - all_coordinates_ang_list.append(direct_coordinates_ang_list_iter) - all_number_of_atoms_list.append(direct_number_of_atoms_list_iter) - all_element_names_list.append(direct_element_names_list_iter) - all_dihedral_atom_numbers_list.append(direct_dihedral_atom_numbers_list_iter) + # check the values against the past ones + if ( + len(all_coordinates_ang_list) == 0 + and len(all_number_of_atoms_list) == 0 + and len(all_element_names_list) == 0 + ): + all_coordinates_ang_list.append( + direct_coordinates_ang_list_iter + ) + all_number_of_atoms_list.append( + direct_number_of_atoms_list_iter + ) + all_element_names_list.append( + direct_element_names_list_iter + ) + all_dihedral_atom_numbers_list.append( + direct_dihedral_atom_numbers_list_iter + ) else: - - all_coordinates_ang_list.append(direct_coordinates_ang_list_iter) + all_coordinates_ang_list.append( + direct_coordinates_ang_list_iter + ) # check if the number_of_atoms are the same for all Gaussian files all_number_of_atoms_list = mdf_math.check_previous_qm_values_match( all_number_of_atoms_list, direct_number_of_atoms_list_iter, - 'number of atoms', - 'Direct Guassian output file', - direct_gaussian_coord_formated_file_name_iter + "number of atoms", + "Direct Guassian output file", + direct_gaussian_coord_formated_file_name_iter, ) # check if the nelement_names are the same for all Gaussian files all_element_names_list = mdf_math.check_previous_qm_values_match( all_element_names_list, direct_element_names_list_iter, - 'element names', - 'Direct Guassian output file', - direct_gaussian_coord_formated_file_name_iter + "element names", + "Direct Guassian output file", + direct_gaussian_coord_formated_file_name_iter, ) # check if the nelement_names are the same for all Gaussian files all_dihedral_atom_numbers_list = mdf_math.check_previous_qm_values_match( all_dihedral_atom_numbers_list, direct_dihedral_atom_numbers_list_iter, - 'dihedral atom numbers', - 'Direct Guassian output file', - direct_gaussian_coord_formated_file_name_iter + "dihedral atom numbers", + "Direct Guassian output file", + direct_gaussian_coord_formated_file_name_iter, ) element_names_list = all_element_names_list[0] @@ -643,13 +724,12 @@ def get_final_gaussian_output_file_data( all_coordinates_ang_list, element_names_list, number_of_atoms, - manual_dihedral_atom_numbers_list + manual_dihedral_atom_numbers_list, ] - def get_gaussian_log_file_data( - qm_log_files_and_entries_to_remove_dict, + qm_log_files_and_entries_to_remove_dict, ): """Get the Guassian/Gausview file data from the log filefor all the optimized configurations. @@ -750,7 +830,10 @@ def get_gaussian_log_file_data( all_number_of_atoms_list = [] all_element_names_list = [] - for log_file_iter, entries_to_remove_list_iter in qm_log_files_and_entries_to_remove_dict.items(): + for ( + log_file_iter, + entries_to_remove_list_iter, + ) in qm_log_files_and_entries_to_remove_dict.items(): # run each log file with open(log_file_iter, "r") as fp: dihedral_scan_line = None @@ -778,55 +861,75 @@ def get_gaussian_log_file_data( # get the starting dihedral scan location, elements, charge, multiplicity and number of atoms (START) # ********************************** # get and mark the initial system setup for a dihedral scan - if len(split_line_m) >= 2 and split_line_m[0] == 'Dihedral' and split_line_m[1] == 'Scan': + if ( + len(split_line_m) >= 2 + and split_line_m[0] == "Dihedral" + and split_line_m[1] == "Scan" + ): dihedral_scan_line = m # get the Guassian molecule charge and multiplicity - if len(split_line_m) >= 4 and \ - split_line_m[0] == "Charge" \ - and split_line_m[1] == "=" \ - and split_line_m[3] == "Multiplicity" \ - and split_line_m[4] == "=": - + if ( + len(split_line_m) >= 4 + and split_line_m[0] == "Charge" + and split_line_m[1] == "=" + and split_line_m[3] == "Multiplicity" + and split_line_m[4] == "=" + ): molecule_charge = split_line_m[2] molecule_multiplicity = split_line_m[5] # check if the molecule charges are the same for all Gaussian files - all_molecule_charge_list = mdf_math.check_previous_qm_values_match( - all_molecule_charge_list, - molecule_charge, - 'molecule charge', - 'Gaussian', - log_file_iter + all_molecule_charge_list = ( + mdf_math.check_previous_qm_values_match( + all_molecule_charge_list, + molecule_charge, + "molecule charge", + "Gaussian", + log_file_iter, + ) ) # check if the molecule multiplicity are the same for all Gaussian files - all_molecule_multiplicity_list = mdf_math.check_previous_qm_values_match( - all_molecule_multiplicity_list, - molecule_multiplicity, - 'molecule multiplicity', - 'Gaussian', - log_file_iter + all_molecule_multiplicity_list = ( + mdf_math.check_previous_qm_values_match( + all_molecule_multiplicity_list, + molecule_multiplicity, + "molecule multiplicity", + "Gaussian", + log_file_iter, + ) ) # use the NAtoms= to get number of atoms - if len(split_line_m) > 2 and number_of_atoms is None and split_line_m[0] == 'NAtoms=': + if ( + len(split_line_m) > 2 + and number_of_atoms is None + and split_line_m[0] == "NAtoms=" + ): number_of_atoms = int(split_line_m[1]) # get the element names spaces_to_element = 2 - if len(split_line_m) == 5 \ - and get_element_names_bool is True \ - and number_of_atoms is not None \ - and split_line_m[0] == 'Condensed' \ - and split_line_m[1] == 'to' \ - and split_line_m[2] == 'atoms' \ - and split_line_m[3] == '(all' \ - and split_line_m[4] == 'electrons):' \ - and len(gaussian_log_file[m + spaces_to_element].split()) > 2: - - for spaces_to_element_i in range(spaces_to_element, spaces_to_element + number_of_atoms): + if ( + len(split_line_m) == 5 + and get_element_names_bool is True + and number_of_atoms is not None + and split_line_m[0] == "Condensed" + and split_line_m[1] == "to" + and split_line_m[2] == "atoms" + and split_line_m[3] == "(all" + and split_line_m[4] == "electrons):" + and len(gaussian_log_file[m + spaces_to_element].split()) + > 2 + ): + for spaces_to_element_i in range( + spaces_to_element, spaces_to_element + number_of_atoms + ): element_names_list.append( - gaussian_log_file[m + spaces_to_element_i].split()[1]) + gaussian_log_file[m + spaces_to_element_i].split()[ + 1 + ] + ) get_element_names_bool = False @@ -841,26 +944,29 @@ def get_gaussian_log_file_data( # get the dihedral atom numbers (in Gaussian numbering starts at 1) # and the dihedral degrees per scan if len(split_line_m) == 8 and dihedral_scan_line is not None: - if split_line_m[0] == "D" \ - and split_line_m[5] == "S" \ - and gaussian_log_file[m - 1].split()[0] == "The" \ - and gaussian_log_file[m - 1].split()[1] == "following": - + if ( + split_line_m[0] == "D" + and split_line_m[5] == "S" + and gaussian_log_file[m - 1].split()[0] == "The" + and gaussian_log_file[m - 1].split()[1] == "following" + ): dihedral_atom_numbers_list = [ int(split_line_m[1]), int(split_line_m[2]), int(split_line_m[3]), - int(split_line_m[4]) + int(split_line_m[4]), ] scan_degrees_per_scan = float(split_line_m[7]) # check if the all the dihedral atom numbers are the same for all Gaussian files - all_dihedral_atom_numbers_list = mdf_math.check_previous_qm_values_match( - all_dihedral_atom_numbers_list, - dihedral_atom_numbers_list, - 'dihedral atom numbers list', - 'Gaussian', - log_file_iter + all_dihedral_atom_numbers_list = ( + mdf_math.check_previous_qm_values_match( + all_dihedral_atom_numbers_list, + dihedral_atom_numbers_list, + "dihedral atom numbers list", + "Gaussian", + log_file_iter, + ) ) # ********************************** @@ -871,12 +977,14 @@ def get_gaussian_log_file_data( # get the number of optimized scans (START) # ********************************** # get the number of optimized scans - if len(split_line_m) >= 6 \ - and split_line_m[0] == "Number" \ - and split_line_m[1] == "of" \ - and split_line_m[2] == "optimizations" \ - and split_line_m[3] == "in" \ - and split_line_m[4] == "scan=": + if ( + len(split_line_m) >= 6 + and split_line_m[0] == "Number" + and split_line_m[1] == "of" + and split_line_m[2] == "optimizations" + and split_line_m[3] == "in" + and split_line_m[4] == "scan=" + ): number_of_optimized_scans = int(split_line_m[5]) # ********************************** # get the number of optimized scans (END) @@ -887,27 +995,29 @@ def get_gaussian_log_file_data( # ********************************** # get the last coordinate point - if len(split_line_m) == 2 \ - and split_line_m[0] == 'Standard' \ - and split_line_m[1] == 'orientation:' \ - and gaussian_log_file[m + 2].split()[0] == 'Center' \ - and gaussian_log_file[m + 2].split()[1] == 'Atomic' \ - and gaussian_log_file[m + 2].split()[2] == 'Atomic' \ - and gaussian_log_file[m + 2].split()[3] == 'Coordinates' \ - and gaussian_log_file[m + 2].split()[4] == '(Angstroms)' \ - and gaussian_log_file[m + 3].split()[0] == 'Number' \ - and gaussian_log_file[m + 3].split()[1] == 'Number' \ - and gaussian_log_file[m + 3].split()[2] == 'Type' \ - and gaussian_log_file[m + 3].split()[3] == 'X' \ - and gaussian_log_file[m + 3].split()[4] == 'Y' \ - and gaussian_log_file[m + 3].split()[5] == 'Z': - + if ( + len(split_line_m) == 2 + and split_line_m[0] == "Standard" + and split_line_m[1] == "orientation:" + and gaussian_log_file[m + 2].split()[0] == "Center" + and gaussian_log_file[m + 2].split()[1] == "Atomic" + and gaussian_log_file[m + 2].split()[2] == "Atomic" + and gaussian_log_file[m + 2].split()[3] == "Coordinates" + and gaussian_log_file[m + 2].split()[4] == "(Angstroms)" + and gaussian_log_file[m + 3].split()[0] == "Number" + and gaussian_log_file[m + 3].split()[1] == "Number" + and gaussian_log_file[m + 3].split()[2] == "Type" + and gaussian_log_file[m + 3].split()[3] == "X" + and gaussian_log_file[m + 3].split()[4] == "Y" + and gaussian_log_file[m + 3].split()[5] == "Z" + ): if isinstance(number_of_atoms, int): coord_list_iter = [] for atom_i in range(0, number_of_atoms): spaces_to_1st_atom_coord = 5 - coor_line_m = gaussian_log_file[m + - spaces_to_1st_atom_coord + atom_i].split() + coor_line_m = gaussian_log_file[ + m + spaces_to_1st_atom_coord + atom_i + ].split() if len(coor_line_m) == 6: coord_list_iter.append( @@ -920,9 +1030,12 @@ def get_gaussian_log_file_data( last_coordinates_ang_list = coord_list_iter - if len(optimized_dihedral_angle_degrees_list) > len(optimized_coordinates_ang_list): + if len(optimized_dihedral_angle_degrees_list) > len( + optimized_coordinates_ang_list + ): optimized_coordinates_ang_list.append( - last_coordinates_ang_list) + last_coordinates_ang_list + ) # ********************************** # get the optimized coordinates (END) @@ -932,16 +1045,21 @@ def get_gaussian_log_file_data( # get energy data in Hartree (START) # ********************************** - if len(split_line_m) >= 5 \ - and split_line_m[0] == 'SCF' \ - and split_line_m[1] == 'Done:' \ - and split_line_m[3] == '=': + if ( + len(split_line_m) >= 5 + and split_line_m[0] == "SCF" + and split_line_m[1] == "Done:" + and split_line_m[3] == "=" + ): energy_hartree_list_iter.append(split_line_m[4]) # only collect parameters (optimized_energy_hartree_list) after the system is optimized - if len(optimized_dihedral_angle_degrees_list) > len(optimized_energy_hartree_list): + if len(optimized_dihedral_angle_degrees_list) > len( + optimized_energy_hartree_list + ): optimized_energy_hartree_list.append( - energy_hartree_list_iter[-1]) + energy_hartree_list_iter[-1] + ) # ********************************** # get energy data in Hartree (START) @@ -950,26 +1068,32 @@ def get_gaussian_log_file_data( # ********************************** # get actual degree from optimization rounded to 3 decimal places (START) # ********************************** - if len(split_line_m) == 8 \ - and split_line_m[0] == '!' \ - and split_line_m[2] == f'D(' \ - f'{dihedral_atom_numbers_list[0]},' \ - f'{dihedral_atom_numbers_list[1]},' \ - f'{dihedral_atom_numbers_list[2]},' \ - f'{dihedral_atom_numbers_list[3]}' \ - f')' \ - and split_line_m[4] == '-DE/DX' \ - and split_line_m[5] == '=' \ - and split_line_m[7] == '!': + if ( + len(split_line_m) == 8 + and split_line_m[0] == "!" + and split_line_m[2] == f"D(" + f"{dihedral_atom_numbers_list[0]}," + f"{dihedral_atom_numbers_list[1]}," + f"{dihedral_atom_numbers_list[2]}," + f"{dihedral_atom_numbers_list[3]}" + f")" + and split_line_m[4] == "-DE/DX" + and split_line_m[5] == "=" + and split_line_m[7] == "!" + ): optimized_dihedral_angle_degrees_list.append( - str(np.round(float(split_line_m[3]), decimals=3))) + str(np.round(float(split_line_m[3]), decimals=3)) + ) # ********************************** # get actual degree from optimization rounded to 3 decimal places (End) # ********************************** - if number_of_optimized_scans != len(optimized_coordinates_ang_list) \ - or number_of_optimized_scans != len(optimized_energy_hartree_list) \ - or number_of_optimized_scans != len(optimized_dihedral_angle_degrees_list): + if ( + number_of_optimized_scans != len(optimized_coordinates_ang_list) + or number_of_optimized_scans != len(optimized_energy_hartree_list) + or number_of_optimized_scans + != len(optimized_dihedral_angle_degrees_list) + ): raise ValueError( f"ERROR: The lengths of " f"the optimized coordinate list 'len(optimized_coordinates_ang_list)' " @@ -983,8 +1107,11 @@ def get_gaussian_log_file_data( f"= {len(number_of_optimized_scans)}." ) - if isinstance(entries_to_remove_list_iter, list) and len(entries_to_remove_list_iter) != 0: - if max(entries_to_remove_list_iter) > number_of_optimized_scans-1: + if ( + isinstance(entries_to_remove_list_iter, list) + and len(entries_to_remove_list_iter) != 0 + ): + if max(entries_to_remove_list_iter) > number_of_optimized_scans - 1: raise ValueError( f"ERROR: For the '{log_file_iter}' log file, " f"the 'entries_to_remove_list_iter' list '{entries_to_remove_list_iter}' " @@ -1005,20 +1132,24 @@ def get_gaussian_log_file_data( ) # check if theelement names are the same for all Gaussian files - all_element_names_list = mdf_math.check_previous_qm_values_match( - all_element_names_list, - element_names_list, - 'element names ', - 'Gaussian', - log_file_iter + all_element_names_list = ( + mdf_math.check_previous_qm_values_match( + all_element_names_list, + element_names_list, + "element names ", + "Gaussian", + log_file_iter, + ) ) - all_number_of_atoms_list = mdf_math.check_previous_qm_values_match( - all_number_of_atoms_list, - number_of_atoms, - 'number of atoms', - 'Gaussian', - log_file_iter + all_number_of_atoms_list = ( + mdf_math.check_previous_qm_values_match( + all_number_of_atoms_list, + number_of_atoms, + "number of atoms", + "Gaussian", + log_file_iter, + ) ) return [ @@ -1027,14 +1158,14 @@ def get_gaussian_log_file_data( all_coordinates_ang_list, element_names_list, number_of_atoms, - dihedral_atom_numbers_list + dihedral_atom_numbers_list, ] def write_qm_data_files( - qm_log_files_and_entries_to_remove_dict, - manual_dihedral_atom_numbers_list=None, - qm_engine="gaussian" + qm_log_files_and_entries_to_remove_dict, + manual_dihedral_atom_numbers_list=None, + qm_engine="gaussian", ): """Write out the optimized QM simulation data from the QM log files. @@ -1141,25 +1272,25 @@ def write_qm_data_files( all_coordinates_ang_list, element_names_list, number_of_atoms, - dihedral_atom_numbers_list - ] = get_gaussian_log_file_data( - qm_log_files_and_entries_to_remove_dict - ) + dihedral_atom_numbers_list, + ] = get_gaussian_log_file_data(qm_log_files_and_entries_to_remove_dict) elif qm_engine == "gaussian_style_final_files": if manual_dihedral_atom_numbers_list == None: - raise TypeError("ERROR: The 'dihedral_atom_numbers_list' is not a list of length 4, " - "and needs entered when using 'gaussian_style_final_files'.") + raise TypeError( + "ERROR: The 'dihedral_atom_numbers_list' is not a list of length 4, " + "and needs entered when using 'gaussian_style_final_files'." + ) [ all_dihedral_angle_degrees_list, all_energy_hartree_list, all_coordinates_ang_list, element_names_list, number_of_atoms, - dihedral_atom_numbers_list + dihedral_atom_numbers_list, ] = get_final_gaussian_output_file_data( qm_log_files_and_entries_to_remove_dict, - manual_dihedral_atom_numbers_list=manual_dihedral_atom_numbers_list + manual_dihedral_atom_numbers_list=manual_dihedral_atom_numbers_list, ) else: @@ -1170,7 +1301,8 @@ def write_qm_data_files( ) # write the gaussian style formatted angle (degrees) and energy output files output_file_dihedral_energy = open( - f"extracted_guassian_data/dihedral.txt", "w") + f"extracted_guassian_data/dihedral.txt", "w" + ) output_file_dihedral_energy.write( f"# Scan of Total Energy\n" @@ -1189,9 +1321,9 @@ def write_qm_data_files( # write the guassian style formatted coordinates file for qm_j in range(0, len(all_dihedral_angle_degrees_list)): - output_file_dihedral_coordinates = open( - f"extracted_guassian_data/dihedral_coords_position_{int(qm_j+1)}.txt", "w" + f"extracted_guassian_data/dihedral_coords_position_{int(qm_j+1)}.txt", + "w", ) output_file_dihedral_coordinates.write( @@ -1201,8 +1333,8 @@ def write_qm_data_files( for qm_k in range(0, number_of_atoms): # atom_number_i starts at 1 atom_number_i = int(qm_k + 1) - highlight = 'No' - display = 'Show' + highlight = "No" + display = "Show" output_file_dihedral_coordinates.write( "{: <8}" "{: <8}" @@ -1219,7 +1351,7 @@ def write_qm_data_files( element_names_list[qm_k], all_coordinates_ang_list[qm_j][qm_k][0], all_coordinates_ang_list[qm_j][qm_k][1], - all_coordinates_ang_list[qm_j][qm_k][2] + all_coordinates_ang_list[qm_j][qm_k][2], ) ) @@ -1227,12 +1359,12 @@ def write_qm_data_files( def get_matching_dihedral_info_and_opls_fitting_data( - fit_dihedral_atom_types, - psf_path_and_filename, - qm_log_files_and_entries_to_remove_dict, - mol2_selection, - qm_engine="gaussian", - manual_dihedral_atom_numbers_list=None + fit_dihedral_atom_types, + psf_path_and_filename, + qm_log_files_and_entries_to_remove_dict, + mol2_selection, + qm_engine="gaussian", + manual_dihedral_atom_numbers_list=None, ): """Get all dihedral angles from the dihedrals which match the fitted dihedrals atom types/classes. @@ -1413,30 +1545,32 @@ def get_matching_dihedral_info_and_opls_fitting_data( f"ERROR: The 'fit_dihedral_atom_types' variable is a {type(fit_dihedral_atom_types)}, not a list" ) - read_psf_file = open(f'{psf_path_and_filename}', "r").readlines() + read_psf_file = open(f"{psf_path_and_filename}", "r").readlines() atom_number_to_atom_type_dict = {} all_dihedral_numbers_as_read_list = [] for psf_iter, psf_line_iter in enumerate(read_psf_file): psf_splitline_iter = psf_line_iter.split() # get the PSF files atom number to atom type/class map dictionary - if len(psf_splitline_iter) == 2 and psf_splitline_iter[1] == '!NATOM': + if len(psf_splitline_iter) == 2 and psf_splitline_iter[1] == "!NATOM": number_of_atoms_iter = int(psf_splitline_iter[0]) if len(read_psf_file[psf_iter + 1].split()) == 8: for atom_i in range(0, number_of_atoms_iter): atom_number_to_atom_type_dict.update( { - int(read_psf_file[psf_iter + atom_i + 1].split()[0]): - read_psf_file[psf_iter + atom_i + 1].split()[5] + int( + read_psf_file[psf_iter + atom_i + 1].split()[0] + ): read_psf_file[psf_iter + atom_i + 1].split()[5] } ) # get the PSF files dihedrals - if len(psf_splitline_iter) == 3 \ - and psf_splitline_iter[1] == '!NPHI:' \ - and psf_splitline_iter[2] == 'dihedrals': - + if ( + len(psf_splitline_iter) == 3 + and psf_splitline_iter[1] == "!NPHI:" + and psf_splitline_iter[2] == "dihedrals" + ): # Get the number of dihedral lines with 2 dihedrals per line (full_lines). # See if the last line has 1 or 2 (half_full_lines), which are only present in the last line. full_lines = int(int(psf_splitline_iter[0]) / 2) @@ -1447,27 +1581,51 @@ def get_matching_dihedral_info_and_opls_fitting_data( # get the first dihedral in the full line all_dihedral_numbers_as_read_list.append( [ - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[0]), - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[1]), - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[2]), - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[3]), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[0] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[1] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[2] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[3] + ), ] ) # get the second dihedral in the full line all_dihedral_numbers_as_read_list.append( [ - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[4]), - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[5]), - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[6]), - int(read_psf_file[psf_iter + - dihedral_i + 1].split()[7]), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[4] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[5] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[6] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 1 + ].split()[7] + ), ] ) @@ -1475,14 +1633,26 @@ def get_matching_dihedral_info_and_opls_fitting_data( if half_full_lines == 1 and full_lines == dihedral_i + 1: all_dihedral_numbers_as_read_list.append( [ - int(read_psf_file[psf_iter + - dihedral_i + 2].split()[0]), - int(read_psf_file[psf_iter + - dihedral_i + 2].split()[1]), - int(read_psf_file[psf_iter + - dihedral_i + 2].split()[2]), - int(read_psf_file[psf_iter + - dihedral_i + 2].split()[3]), + int( + read_psf_file[ + psf_iter + dihedral_i + 2 + ].split()[0] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 2 + ].split()[1] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 2 + ].split()[2] + ), + int( + read_psf_file[ + psf_iter + dihedral_i + 2 + ].split()[3] + ), ] ) @@ -1492,7 +1662,6 @@ def get_matching_dihedral_info_and_opls_fitting_data( fit_dihedral_atom_types[2], fit_dihedral_atom_types[1], fit_dihedral_atom_types[0], - ] # check for a forward and revers match, including wildcard combinations, for the @@ -1504,14 +1673,19 @@ def get_matching_dihedral_info_and_opls_fitting_data( dih_atom_type_p = [] for iter_q in range(0, len(dih_num_p)): dih_atom_type_p.append( - atom_number_to_atom_type_dict[dih_num_p[iter_q]]) + atom_number_to_atom_type_dict[dih_num_p[iter_q]] + ) # check for the input dihedral fit and reversed dihedral fit match_dihedral_atom_types_4_bool_list = [False, False, False, False] match_reverse_dihedral_atom_types_4_bool_list = [ - False, False, False, False] + False, + False, + False, + False, + ] for iter_r, dih_atom_type_r in enumerate(dih_atom_type_p): - if dih_atom_type_r in ['x', 'X', '*', '']: + if dih_atom_type_r in ["x", "X", "*", ""]: match_dihedral_atom_types_4_bool_list[iter_r] = True match_reverse_dihedral_atom_types_4_bool_list[iter_r] = True @@ -1525,8 +1699,10 @@ def get_matching_dihedral_info_and_opls_fitting_data( # if so save the atom numbers # matching_dihedral_types_by_atom_numbers_list = [] # matching_dihedral_types_by_atom_type_list = [] - if False not in match_dihedral_atom_types_4_bool_list \ - or False not in match_reverse_dihedral_atom_types_4_bool_list: + if ( + False not in match_dihedral_atom_types_4_bool_list + or False not in match_reverse_dihedral_atom_types_4_bool_list + ): matching_dihedral_types_by_atom_numbers_list.append(dih_num_p) matching_dihedral_types_by_atom_type_list.append(dih_atom_type_p) @@ -1542,25 +1718,27 @@ def get_matching_dihedral_info_and_opls_fitting_data( coordinates_ang_list, all_element_names_list, number_of_atoms_list, - dihedral_atom_numbers_list + dihedral_atom_numbers_list, ] = get_gaussian_log_file_data( qm_log_files_and_entries_to_remove_dict ) elif qm_engine == "gaussian_style_final_files": if manual_dihedral_atom_numbers_list == None: - raise TypeError("ERROR: The 'manual_dihedral_atom_numbers_list' is not a list of length 4, " - "and needs entered when using 'direct_gaussian_final_files'.") + raise TypeError( + "ERROR: The 'manual_dihedral_atom_numbers_list' is not a list of length 4, " + "and needs entered when using 'direct_gaussian_final_files'." + ) [ dihedral_angle_degrees_list, energy_hartree_list, coordinates_ang_list, all_element_names_list, number_of_atoms_list, - dihedral_atom_numbers_list + dihedral_atom_numbers_list, ] = get_final_gaussian_output_file_data( qm_log_files_and_entries_to_remove_dict, - manual_dihedral_atom_numbers_list=manual_dihedral_atom_numbers_list + manual_dihedral_atom_numbers_list=manual_dihedral_atom_numbers_list, ) else: raise ValueError( @@ -1569,8 +1747,10 @@ def get_matching_dihedral_info_and_opls_fitting_data( ) # check if QM and mol2 file elements match - [atom_name_mol2_list, element_name_mol2_list] = \ - get_atom_names_and_elements_from_mol2(mol2_selection) + [ + atom_name_mol2_list, + element_name_mol2_list, + ] = get_atom_names_and_elements_from_mol2(mol2_selection) if all_element_names_list != element_name_mol2_list: raise ValueError( f"ERROR: The QM elements do not match the mol2 file elements, in order. \n" @@ -1586,8 +1766,13 @@ def get_matching_dihedral_info_and_opls_fitting_data( atom_number_to_atom_type_dict[dihedral_atom_numbers_list[3]], ] - for iter_u, dih_num_u in enumerate(matching_dihedral_types_by_atom_type_list): - if dih_num_u not in [fit_dihedral_atom_types, fit_dihedral_atom_types_reversed]: + for iter_u, dih_num_u in enumerate( + matching_dihedral_types_by_atom_type_list + ): + if dih_num_u not in [ + fit_dihedral_atom_types, + fit_dihedral_atom_types_reversed, + ]: raise ValueError( f"ERROR: The extracted identical atom dihedral types = {dih_num_u} " f"are not equal to the fitted dihedral type " @@ -1597,7 +1782,10 @@ def get_matching_dihedral_info_and_opls_fitting_data( ) # check the atom numbers of the PSF against QM - if qm_atom_types_from_psf_map not in [fit_dihedral_atom_types, fit_dihedral_atom_types_reversed]: + if qm_atom_types_from_psf_map not in [ + fit_dihedral_atom_types, + fit_dihedral_atom_types_reversed, + ]: raise ValueError( f"ERROR: When the QM ({qm_engine}) dihedral atoms = {qm_atom_types_from_psf_map}, " f"when they are mapped to atom types/classes via the PSF data, which " @@ -1614,12 +1802,15 @@ def get_matching_dihedral_info_and_opls_fitting_data( for qm_scan_i, coords_qm_scan_i in enumerate(coordinates_ang_list): dih_coor_iter_list = [] dih_phi_iter_list = [] - for dih_q, dih_list_4_atom_number_q in enumerate(matching_dihedral_types_by_atom_numbers_list): + for dih_q, dih_list_4_atom_number_q in enumerate( + matching_dihedral_types_by_atom_numbers_list + ): atom_coor_iter_list = [] for dih_atom_number_q in dih_list_4_atom_number_q: # added - 1 to below because atom numbering starts at 1 and Python lists at 0. atom_coor_iter_list.append( - coords_qm_scan_i[dih_atom_number_q - 1]) + coords_qm_scan_i[dih_atom_number_q - 1] + ) # get the dihedral coordinates lists for each QM scan dih_coor_iter_list.append(atom_coor_iter_list) @@ -1636,12 +1827,15 @@ def get_matching_dihedral_info_and_opls_fitting_data( ) all_matching_dihedral_coordinates_angstroms_added_to_k_values_list.append( - dih_coor_iter_list) + dih_coor_iter_list + ) all_matching_dihedral_phi_degrees_added_to_k_values_list.append( - dih_phi_iter_list) + dih_phi_iter_list + ) all_sum_opls_const_1_plus_or_minus_cos_n_list.append( mdf_math.sum_opls_const_1_plus_or_minus_cos_n_values( - dih_phi_iter_list) + dih_phi_iter_list + ) ) return [ @@ -1649,18 +1843,18 @@ def get_matching_dihedral_info_and_opls_fitting_data( matching_dihedral_types_by_atom_type_list, all_matching_dihedral_coordinates_angstroms_added_to_k_values_list, all_matching_dihedral_phi_degrees_added_to_k_values_list, - all_sum_opls_const_1_plus_or_minus_cos_n_list + all_sum_opls_const_1_plus_or_minus_cos_n_list, ] def change_gomc_ff_file_dihedral_values( - read_gomc_ff_filename, - new_gomc_ff_filename, - fit_dihedral_atom_types, - fit_dihedral_opls_k_0_1_2_3_4_values=[0, 0, 0, 0, 0], - zeroed_dihedral_atom_types=None, + read_gomc_ff_filename, + new_gomc_ff_filename, + fit_dihedral_atom_types, + fit_dihedral_opls_k_0_1_2_3_4_values=[0, 0, 0, 0, 0], + zeroed_dihedral_atom_types=None, ): - '''Rewrite the GOMC/CHARMM style force field file with modified fit dihedral values and other zeroed dihedrals. + """Rewrite the GOMC/CHARMM style force field file with modified fit dihedral values and other zeroed dihedrals. This rewrites the the GOMC/CHARMM style force field file with modified/entered values for the dihedral being fit ('fit_dihedral_opls_k_0_1_2_3_4_values'). It also allows @@ -1696,44 +1890,54 @@ def change_gomc_ff_file_dihedral_values( fit new dihedral values 'fit_dihedral_opls_k_0_1_2_3_4_values', and any other dihedrals that need to be zeroed out ('zeroed_dihedral_atom_types') for the 'fit_dihedral_atom_types' dihedral to be fit. - ''' + """ # check if the fitted dihedral is input correctly - if not isinstance(fit_dihedral_atom_types, list) \ - or len(fit_dihedral_atom_types) != 4 \ - or not isinstance(fit_dihedral_atom_types[0], str) \ - or not isinstance(fit_dihedral_atom_types[1], str) \ - or not isinstance(fit_dihedral_atom_types[2], str) \ - or not isinstance(fit_dihedral_atom_types[3], str): + if ( + not isinstance(fit_dihedral_atom_types, list) + or len(fit_dihedral_atom_types) != 4 + or not isinstance(fit_dihedral_atom_types[0], str) + or not isinstance(fit_dihedral_atom_types[1], str) + or not isinstance(fit_dihedral_atom_types[2], str) + or not isinstance(fit_dihedral_atom_types[3], str) + ): raise TypeError( f"ERROR: The input 'fit_dihedral_atom_types' variable = {fit_dihedral_atom_types}, " f"but it needs to be a list of 4 strings, " - f"where the strings are the atom types/classes. Example: ['HC', 'CT', 'CT', 'HC'].") + f"where the strings are the atom types/classes. Example: ['HC', 'CT', 'CT', 'HC']." + ) # check if the other dihedral which need zeroed are input correctly zeroed_dihedral_atom_types_error = ( f"ERROR: The zeroed_dihedral_atom_types' variable need to be 'None, " f"a list of strings, " f"or a nested list containing 1 or more list(s) of 4 strings, " - f"where the strings are the atom types/classes.") + f"where the strings are the atom types/classes." + ) if isinstance(zeroed_dihedral_atom_types, list): - if len(zeroed_dihedral_atom_types) == 4 \ - and isinstance(zeroed_dihedral_atom_types[0], str) \ - and isinstance(zeroed_dihedral_atom_types[1], str) \ - and isinstance(zeroed_dihedral_atom_types[2], str) \ - and isinstance(zeroed_dihedral_atom_types[3], str): + if ( + len(zeroed_dihedral_atom_types) == 4 + and isinstance(zeroed_dihedral_atom_types[0], str) + and isinstance(zeroed_dihedral_atom_types[1], str) + and isinstance(zeroed_dihedral_atom_types[2], str) + and isinstance(zeroed_dihedral_atom_types[3], str) + ): # make it a nested list for the other files input zeroed_dihedral_atom_types = [zeroed_dihedral_atom_types] - elif len(zeroed_dihedral_atom_types) >= 1 and isinstance(zeroed_dihedral_atom_types, list): + elif len(zeroed_dihedral_atom_types) >= 1 and isinstance( + zeroed_dihedral_atom_types, list + ): for list_i in zeroed_dihedral_atom_types: if not len(list_i) == 4: raise TypeError(zeroed_dihedral_atom_types_error) - if isinstance(list_i[0], str) \ - and isinstance(list_i[1], str) \ - and isinstance(list_i[2], str) \ - and isinstance(list_i[3], str): + if ( + isinstance(list_i[0], str) + and isinstance(list_i[1], str) + and isinstance(list_i[2], str) + and isinstance(list_i[3], str) + ): raise TypeError(zeroed_dihedral_atom_types_error) elif not isinstance(zeroed_dihedral_atom_types, type(None)): @@ -1754,17 +1958,19 @@ def change_gomc_ff_file_dihedral_values( # create dictionary for fitted dihedral types and its status of being written to the ff file status_written_fit_dihedral_atom_types_dict = { - str(fit_dihedral_atom_types): False} + str(fit_dihedral_atom_types): False + } # create dictionary for fitted dihedral types to be zeroed and its status of being written to the ff file status_written_zeroed_dihedral_atom_types_dict = {} if zeroed_dihedral_atom_types is not None: for other_i in zeroed_dihedral_atom_types: status_written_zeroed_dihedral_atom_types_dict.update( - {str(other_i): False}) + {str(other_i): False} + ) # write the new GOMC force field file with the selected dihedrals zeroed out - gomc_modified_kvalues_ff_file = open(f'{new_gomc_ff_filename}', "w") + gomc_modified_kvalues_ff_file = open(f"{new_gomc_ff_filename}", "w") if zeroed_dihedral_atom_types is None: gomc_modified_kvalues_ff_file.write( f"* This file was modified from the original GOMC FF file, by zeroing out the " @@ -1790,17 +1996,31 @@ def change_gomc_ff_file_dihedral_values( # if the correct line(s) added the changed dihedral value to the set k-value (Kchi) if len(split_line_m) == 12: # get the forward and reversed dihedral, as it could be printed either way - dih_m = [split_line_m[0], split_line_m[1], - split_line_m[2], split_line_m[3]] - dih_m_reverse = [split_line_m[3], split_line_m[2], - split_line_m[1], split_line_m[0]] + dih_m = [ + split_line_m[0], + split_line_m[1], + split_line_m[2], + split_line_m[3], + ] + dih_m_reverse = [ + split_line_m[3], + split_line_m[2], + split_line_m[1], + split_line_m[0], + ] # set the fitted dihedral types to the 'fit_dihedral_opls_k_0_1_2_3_4_values' # in the GOMC/CHARMM style FF file - if (str(dih_m) or str(dih_m_reverse)) in list(status_written_fit_dihedral_atom_types_dict.keys()) \ - and status_written_fit_dihedral_atom_types_dict[str(dih_m)] is False \ - and (dih_m == fit_dihedral_atom_types or dih_m_reverse == fit_dihedral_atom_types): - + if ( + (str(dih_m) or str(dih_m_reverse)) + in list(status_written_fit_dihedral_atom_types_dict.keys()) + and status_written_fit_dihedral_atom_types_dict[str(dih_m)] + is False + and ( + dih_m == fit_dihedral_atom_types + or dih_m_reverse == fit_dihedral_atom_types + ) + ): # get the opls dihedrals and convert them to CHARMM style periodic # periodic_dihedral_k_n_d_values = # [[K0, n0, d0], @@ -1814,7 +2034,7 @@ def change_gomc_ff_file_dihedral_values( fit_dihedral_opls_k_0_1_2_3_4_values[1], fit_dihedral_opls_k_0_1_2_3_4_values[2], fit_dihedral_opls_k_0_1_2_3_4_values[3], - fit_dihedral_opls_k_0_1_2_3_4_values[4] + fit_dihedral_opls_k_0_1_2_3_4_values[4], ) if all_k_values_zero_fit_dihedral_atom_types_bool is True: @@ -1827,14 +2047,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[1][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[1][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[1][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -1855,14 +2075,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[0][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[0][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[0][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -1882,14 +2102,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[1][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[1][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[1][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -1909,14 +2129,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[2][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[2][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[2][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -1936,14 +2156,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[3][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[3][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[3][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -1963,14 +2183,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[4][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[4][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[4][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -1990,14 +2210,14 @@ def change_gomc_ff_file_dihedral_values( str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[5][0], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), str(int(periodic_dihedral_k_n_d_values[5][1])), str( mdf_math.round_to_sig_figs( periodic_dihedral_k_n_d_values[5][2], - sig_figs=number_sig_fig_for_ff_file + sig_figs=number_sig_fig_for_ff_file, ) ), split_line_m[8], @@ -2007,16 +2227,22 @@ def change_gomc_ff_file_dihedral_values( ) ) - status_written_fit_dihedral_atom_types_dict[str( - dih_m)] = True + status_written_fit_dihedral_atom_types_dict[ + str(dih_m) + ] = True # set the zeroed dihedral types to zero in the GOMC/CHARMM style FF file - elif (str(dih_m) or str(dih_m_reverse)) in list(status_written_zeroed_dihedral_atom_types_dict.keys()) \ - and zeroed_dihedral_atom_types is not None \ - and status_written_zeroed_dihedral_atom_types_dict[str(dih_m)] is False \ - and (dih_m in zeroed_dihedral_atom_types - or dih_m_reverse in zeroed_dihedral_atom_types): - + elif ( + (str(dih_m) or str(dih_m_reverse)) + in list(status_written_zeroed_dihedral_atom_types_dict.keys()) + and zeroed_dihedral_atom_types is not None + and status_written_zeroed_dihedral_atom_types_dict[str(dih_m)] + is False + and ( + dih_m in zeroed_dihedral_atom_types + or dih_m_reverse in zeroed_dihedral_atom_types + ) + ): # get the opls dihedrals and convert them to CHARMM style periodic # periodic_dihedral_k_n_d_values = # [[K0, n0, d0], @@ -2033,15 +2259,14 @@ def change_gomc_ff_file_dihedral_values( split_line_m[3], str( mdf_math.round_to_sig_figs( - 0, - sig_figs=number_sig_fig_for_ff_file + 0, sig_figs=number_sig_fig_for_ff_file ) ), str(int(1)), str( - mdf_math.round_to_sig_figs(180.0, - sig_figs=number_sig_fig_for_ff_file - ) + mdf_math.round_to_sig_figs( + 180.0, sig_figs=number_sig_fig_for_ff_file + ) ), split_line_m[8], split_line_m[9], @@ -2050,26 +2275,28 @@ def change_gomc_ff_file_dihedral_values( ) ) - status_written_zeroed_dihedral_atom_types_dict[str( - dih_m)] = True + status_written_zeroed_dihedral_atom_types_dict[ + str(dih_m) + ] = True elif ( - str(dih_m) not in list( - status_written_fit_dihedral_atom_types_dict.keys()) - and - str(dih_m_reverse) not in list( - status_written_fit_dihedral_atom_types_dict.keys()) - ) \ - and ( - str(dih_m) not in list( - status_written_zeroed_dihedral_atom_types_dict.keys()) - and - str(dih_m_reverse) not in list( - status_written_zeroed_dihedral_atom_types_dict.keys()) + str(dih_m) + not in list(status_written_fit_dihedral_atom_types_dict.keys()) + and str(dih_m_reverse) + not in list(status_written_fit_dihedral_atom_types_dict.keys()) + ) and ( + str(dih_m) + not in list( + status_written_zeroed_dihedral_atom_types_dict.keys() + ) + and str(dih_m_reverse) + not in list( + status_written_zeroed_dihedral_atom_types_dict.keys() + ) ): - gomc_modified_kvalues_ff_file.write(f'{line_m}') + gomc_modified_kvalues_ff_file.write(f"{line_m}") else: - gomc_modified_kvalues_ff_file.write(f'{line_m}') + gomc_modified_kvalues_ff_file.write(f"{line_m}") gomc_modified_kvalues_ff_file.close() diff --git a/mosdef_dihedral_fit/utils/io.py b/mosdef_dihedral_fit/utils/io.py index 6d99492..5387ee5 100644 --- a/mosdef_dihedral_fit/utils/io.py +++ b/mosdef_dihedral_fit/utils/io.py @@ -19,5 +19,7 @@ def get_mosdef_dihedral_fit_fn(filename): "mosdef_dihedral_fit", os.path.join("utils", "files", filename) ) if not os.path.exists(full_path_and_filename): - raise ValueError(f"ERROR: The {full_path_and_filename} does not exists.") + raise ValueError( + f"ERROR: The {full_path_and_filename} does not exists." + ) return full_path_and_filename diff --git a/mosdef_dihedral_fit/utils/math_operations.py b/mosdef_dihedral_fit/utils/math_operations.py index 01d81fe..83730ad 100755 --- a/mosdef_dihedral_fit/utils/math_operations.py +++ b/mosdef_dihedral_fit/utils/math_operations.py @@ -1,26 +1,27 @@ -import numpy as np import math +import numpy as np + def round_to_sig_figs(value, sig_figs=3): """Round a number to the selected number of significant figures. - Round a number to the selected number of significant figures. - - Parameters - ---------- - value: int or float - The number that will be rounded to the selected number of - significant figures. - sig_figs: int, default=3 - The number significant figures that the 'value' variable - will be rounded too. If sig_fig=0, it will return 0.0. - - Returns - ------- - value_rounded_to_sig_figs: float - The input 'value' variable rounded to the selected number - significant figures. If sig_fig=0, it will return 0.0. + Round a number to the selected number of significant figures. + + Parameters + ---------- + value: int or float + The number that will be rounded to the selected number of + significant figures. + sig_figs: int, default=3 + The number significant figures that the 'value' variable + will be rounded too. If sig_fig=0, it will return 0.0. + + Returns + ------- + value_rounded_to_sig_figs: float + The input 'value' variable rounded to the selected number + significant figures. If sig_fig=0, it will return 0.0. """ if value == 0: value_rounded_to_sig_figs = 0 @@ -38,6 +39,7 @@ def round_to_sig_figs(value, sig_figs=3): # (START) # ************************************************************** + def normalize_vector(vector): """Generates the normalized vector from a given vector. @@ -100,8 +102,9 @@ def angle_between_2_vectors(vector_1, vector_2): f"angle = arccos[(vector_1 dot vector_2)/(|vector_1||vector_2|)]" ) - arc_cos_value = np.dot(normal_vector_1, normal_vector_2) / \ - (np.linalg.norm(vector_1) * np.linalg.norm(vector_2)) + arc_cos_value = np.dot(normal_vector_1, normal_vector_2) / ( + np.linalg.norm(vector_1) * np.linalg.norm(vector_2) + ) # ensure arc_cos_value is -1<= arc_cos_value <= 1 # ... not 1.000000001 or -1.000000001 or it will yield 'nan' @@ -117,10 +120,10 @@ def angle_between_2_vectors(vector_1, vector_2): def dihedral_angle( - atom_xyz_coord_1, - atom_xyz_coord_2, - atom_xyz_coord_3, - atom_xyz_coord_4, + atom_xyz_coord_1, + atom_xyz_coord_2, + atom_xyz_coord_3, + atom_xyz_coord_4, ): """Gets the dihedral angle between the four (4) atom coordinates given in cartesian coordinates. @@ -147,12 +150,14 @@ def dihedral_angle( The dihedral angle, in degrees, between the four (4) atoms. """ # check if any atom coordinates are the same - if list(atom_xyz_coord_1) == list(atom_xyz_coord_2) \ - or list(atom_xyz_coord_1) == list(atom_xyz_coord_3) \ - or list(atom_xyz_coord_1) == list(atom_xyz_coord_4) \ - or list(atom_xyz_coord_2) == list(atom_xyz_coord_3) \ - or list(atom_xyz_coord_2) == list(atom_xyz_coord_4) \ - or list(atom_xyz_coord_3) == list(atom_xyz_coord_4): + if ( + list(atom_xyz_coord_1) == list(atom_xyz_coord_2) + or list(atom_xyz_coord_1) == list(atom_xyz_coord_3) + or list(atom_xyz_coord_1) == list(atom_xyz_coord_4) + or list(atom_xyz_coord_2) == list(atom_xyz_coord_3) + or list(atom_xyz_coord_2) == list(atom_xyz_coord_4) + or list(atom_xyz_coord_3) == list(atom_xyz_coord_4) + ): raise ValueError( f"ERROR: The one or more of the atom coordinates are the same when entered into \n" f"the 'get_dihedral_angle' functions. In order, the entered atom coordinates: \n" @@ -178,23 +183,30 @@ def dihedral_angle( normal_vector_for_atoms_1_2_3_plane = ( # np.cross(vector_between_atoms_1_2, vector_between_atoms_2_3) / normalize_vector( - np.cross(vector_between_atoms_1_2, vector_between_atoms_2_3)) + np.cross(vector_between_atoms_1_2, vector_between_atoms_2_3) + ) ) normal_vector_for_atoms_2_3_4_plane = ( # np.cross(vector_between_atoms_2_3, vector_between_atoms_3_4) / normalize_vector( - np.cross(vector_between_atoms_2_3, vector_between_atoms_3_4)) + np.cross(vector_between_atoms_2_3, vector_between_atoms_3_4) + ) ) dihedral_angle_degrees = float( angle_between_2_vectors( normal_vector_for_atoms_1_2_3_plane, - normal_vector_for_atoms_2_3_4_plane + normal_vector_for_atoms_2_3_4_plane, ) ) # correct the dihedral angle ('dihedral_angle_degrees') for location, rotation direction - if not np.dot(normal_vector_for_atoms_1_2_3_plane, vector_between_atoms_3_4) >= 0: + if ( + not np.dot( + normal_vector_for_atoms_1_2_3_plane, vector_between_atoms_3_4 + ) + >= 0 + ): dihedral_angle_degrees = -dihedral_angle_degrees if dihedral_angle_degrees == 180: @@ -202,6 +214,7 @@ def dihedral_angle( return dihedral_angle_degrees + # ************************************************************** # dihedral angles calculations # (End) @@ -209,11 +222,7 @@ def dihedral_angle( def check_previous_qm_values_match( - all_value_list, - current_value, - value_name, - qm_engine, - log_file_name + all_value_list, current_value, value_name, qm_engine, log_file_name ): """Checks if the QM log file read values match the last value in the appended list. @@ -327,21 +336,22 @@ def sum_opls_const_1_plus_or_minus_cos_n_values(phi_list): const_1_minus_Cos_4_phi = 0 for phi_i, phi_value_i in enumerate(phi_list): - const_1_plus_Cos_1_phi += (1 + np.cos(1 * phi_value_i * np.pi / 180)) - const_1_minus_Cos_2_phi += (1 - np.cos(2 * phi_value_i * np.pi / 180)) - const_1_plus_Cos_3_phi += (1 + np.cos(3 * phi_value_i * np.pi / 180)) - const_1_minus_Cos_4_phi += (1 - np.cos(4 * phi_value_i * np.pi / 180)) + const_1_plus_Cos_1_phi += 1 + np.cos(1 * phi_value_i * np.pi / 180) + const_1_minus_Cos_2_phi += 1 - np.cos(2 * phi_value_i * np.pi / 180) + const_1_plus_Cos_3_phi += 1 + np.cos(3 * phi_value_i * np.pi / 180) + const_1_minus_Cos_4_phi += 1 - np.cos(4 * phi_value_i * np.pi / 180) const_1_plus_or_minus_Cos_n_phi = [ const_1_minus_Cos_0_phi, const_1_plus_Cos_1_phi, const_1_minus_Cos_2_phi, const_1_plus_Cos_3_phi, - const_1_minus_Cos_4_phi + const_1_minus_Cos_4_phi, ] return const_1_plus_or_minus_Cos_n_phi + # opls dihedral function using for all combinations @@ -472,22 +482,43 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): The OPLS dihedral energy from the valid phi_data and k-values (i.e., k1 in this case). """ - cos_powers, \ - scanned_phi,\ - const_1_minus_Cos_0_phi_data, \ - const_1_plus_Cos_1_phi_data, \ - const_1_minus_Cos_2_phi_data, \ - const_1_plus_Cos_3_phi_data, \ - const_1_minus_Cos_4_phi_data = cos_powers_phi_and_constants_data + ( + cos_powers, + scanned_phi, + const_1_minus_Cos_0_phi_data, + const_1_plus_Cos_1_phi_data, + const_1_minus_Cos_2_phi_data, + const_1_plus_Cos_3_phi_data, + const_1_minus_Cos_4_phi_data, + ) = cos_powers_phi_and_constants_data # check if all_sum_opls_const_1_plus_or_minus_cos_n_list is correct size: - if not isinstance(const_1_minus_Cos_0_phi_data, (list, np.ndarray, int, float, type(None))) \ - or not isinstance(const_1_minus_Cos_0_phi_data, (list, np.ndarray, int, float, type(None))) \ - or not isinstance(const_1_plus_Cos_1_phi_data, (list, np.ndarray, int, float, type(None))) \ - or not isinstance(const_1_minus_Cos_2_phi_data, (list, np.ndarray, int, float, type(None))) \ - or not isinstance(const_1_plus_Cos_3_phi_data, (list, np.ndarray, int, float, type(None))) \ - or not isinstance(const_1_minus_Cos_4_phi_data, (list, np.ndarray, int, float, type(None))): - + if ( + not isinstance( + const_1_minus_Cos_0_phi_data, + (list, np.ndarray, int, float, type(None)), + ) + or not isinstance( + const_1_minus_Cos_0_phi_data, + (list, np.ndarray, int, float, type(None)), + ) + or not isinstance( + const_1_plus_Cos_1_phi_data, + (list, np.ndarray, int, float, type(None)), + ) + or not isinstance( + const_1_minus_Cos_2_phi_data, + (list, np.ndarray, int, float, type(None)), + ) + or not isinstance( + const_1_plus_Cos_3_phi_data, + (list, np.ndarray, int, float, type(None)), + ) + or not isinstance( + const_1_minus_Cos_4_phi_data, + (list, np.ndarray, int, float, type(None)), + ) + ): raise TypeError( "ERROR: the 'cos_powers_phi_and_constants_data' values (" "const_1_minus_Cos_0_phi_data," @@ -501,16 +532,15 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): f"const_1_minus_Cos_2_phi_data = {const_1_minus_Cos_2_phi_data}, \n" f"const_1_plus_Cos_3_phi_data = {const_1_plus_Cos_3_phi_data}, \n" f"const_1_minus_Cos_4_phi_data = {const_1_minus_Cos_4_phi_data}." - ) if ( - const_1_minus_Cos_0_phi_data is None - or const_1_minus_Cos_0_phi_data is None - or const_1_plus_Cos_1_phi_data is None - or const_1_minus_Cos_2_phi_data is None - or const_1_plus_Cos_3_phi_data is None - or const_1_minus_Cos_4_phi_data is None + const_1_minus_Cos_0_phi_data is None + or const_1_minus_Cos_0_phi_data is None + or const_1_plus_Cos_1_phi_data is None + or const_1_minus_Cos_2_phi_data is None + or const_1_plus_Cos_3_phi_data is None + or const_1_minus_Cos_4_phi_data is None ) and ( const_1_minus_Cos_0_phi_data != const_1_minus_Cos_0_phi_data @@ -557,13 +587,15 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): f"scanned_phi = {scanned_phi}." ) else: - if len(cos_powers) \ - != len(scanned_phi) \ - != len(const_1_minus_Cos_0_phi_data) \ - != len(const_1_plus_Cos_1_phi_data) \ - != len(const_1_minus_Cos_2_phi_data) \ - != len(const_1_plus_Cos_3_phi_data) \ - != len(const_1_minus_Cos_4_phi_data): + if ( + len(cos_powers) + != len(scanned_phi) + != len(const_1_minus_Cos_0_phi_data) + != len(const_1_plus_Cos_1_phi_data) + != len(const_1_minus_Cos_2_phi_data) + != len(const_1_plus_Cos_3_phi_data) + != len(const_1_minus_Cos_4_phi_data) + ): raise ValueError( f"ERROR: the 'cos_powers_phi_and_constants_data' values (cos_powers, phi_data), " f"are not the same length -> " @@ -580,7 +612,8 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): for z in range(0, len(cos_powers)): if cos_powers[0] != cos_powers[z]: raise ValueError( - "ERROR: the 'cos_powers' are not all the same for a given fit.") + "ERROR: the 'cos_powers' are not all the same for a given fit." + ) cos_powers_idential_value = cos_powers[0] @@ -591,10 +624,10 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): ) if isinstance(cos_powers_idential_value, str): - cos_powers_modified = '' + cos_powers_modified = "" for p in range(0, len(cos_powers_idential_value)): - if cos_powers[p] == '-': - cos_powers_modified += '_' + if cos_powers[p] == "-": + cos_powers_modified += "_" else: cos_powers_modified += cos_powers_idential_value[p] @@ -602,11 +635,38 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): cos_powers_modified = cos_powers_idential_value # check for acceptable cos_powers - if cos_powers_modified not in \ - ['1', '2', '3', '4', '1_3', '2_4', '1_2', '3_4', '1_2_3', '1_2_3_4', - 1, 2, 3, 4, 13, 24, 12, 34, 123, 1234, - 1., 2., 3., 4., 13., 24., 12., 34., 123., 1234. - ]: + if cos_powers_modified not in [ + "1", + "2", + "3", + "4", + "1_3", + "2_4", + "1_2", + "3_4", + "1_2_3", + "1_2_3_4", + 1, + 2, + 3, + 4, + 13, + 24, + 12, + 34, + 123, + 1234, + 1.0, + 2.0, + 3.0, + 4.0, + 13.0, + 24.0, + 12.0, + 34.0, + 123.0, + 1234.0, + ]: raise ValueError( f"ERROR: {cos_powers} was entered for the cos_powers variable, but the only " f"available options are " @@ -616,141 +676,197 @@ def opls_dihedral(cos_powers_phi_and_constants_data, k0, k1, k2, k3, k4): f" 1., 2., 3., 4., 13., 24., 12., 34., 123., 1234.]" ) - if cos_powers_modified in ['1', 1, 1.]: + if cos_powers_modified in ["1", 1, 1.0]: # NOTE: THE ALL BUT THE 'kx' VALUES ARE REPLACES WITH A CONSTANT, if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180) - ) + dihedral_energy = ( + 1 / 2 * (+k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180))) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k1 * const_1_plus_Cos_1_phi_data - ) + dihedral_energy = 1 / 2 * (+k1 * const_1_plus_Cos_1_phi_data) - elif cos_powers_modified in ['2', 2, 2.]: + elif cos_powers_modified in ["2", 2, 2.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 / 2 * (+k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180))) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k2 * const_1_minus_Cos_2_phi_data - ) + dihedral_energy = 1 / 2 * (+k2 * const_1_minus_Cos_2_phi_data) - elif cos_powers_modified in ['3', 3, 3.]: + elif cos_powers_modified in ["3", 3, 3.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 / 2 * (+k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180))) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k3 * const_1_plus_Cos_3_phi_data - ) + dihedral_energy = 1 / 2 * (+k3 * const_1_plus_Cos_3_phi_data) - elif cos_powers_modified in ['4', 4, 4.]: + elif cos_powers_modified in ["4", 4, 4.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 / 2 * (+k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180))) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k4 * const_1_minus_Cos_4_phi_data - ) + dihedral_energy = 1 / 2 * (+k4 * const_1_minus_Cos_4_phi_data) - elif cos_powers_modified in ['1_3', 13, 13.]: + elif cos_powers_modified in ["1_3", 13, 13.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) - + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) + + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + ) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k1 * const_1_plus_Cos_1_phi_data - + k3 * const_1_plus_Cos_3_phi_data + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * const_1_plus_Cos_1_phi_data + + k3 * const_1_plus_Cos_3_phi_data + ) ) - elif cos_powers_modified in ['2_4', 24, 24.]: + elif cos_powers_modified in ["2_4", 24, 24.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) - + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 + / 2 + * ( + +k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) + + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + ) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k2 * const_1_minus_Cos_2_phi_data - + k4 * const_1_minus_Cos_4_phi_data + dihedral_energy = ( + 1 + / 2 + * ( + +k2 * const_1_minus_Cos_2_phi_data + + k4 * const_1_minus_Cos_4_phi_data + ) ) - elif cos_powers_modified in ['3_4', 34, 34.]: + elif cos_powers_modified in ["3_4", 34, 34.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) - + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 + / 2 + * ( + +k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + ) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k3 * const_1_plus_Cos_3_phi_data - + k4 * const_1_minus_Cos_4_phi_data + dihedral_energy = ( + 1 + / 2 + * ( + +k3 * const_1_plus_Cos_3_phi_data + + k4 * const_1_minus_Cos_4_phi_data + ) ) - elif cos_powers_modified in ['1_2', 12, 12.]: + elif cos_powers_modified in ["1_2", 12, 12.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) - + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) + + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) + ) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k1 * const_1_plus_Cos_1_phi_data - + k2 * const_1_minus_Cos_2_phi_data + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * const_1_plus_Cos_1_phi_data + + k2 * const_1_minus_Cos_2_phi_data + ) ) - elif cos_powers_modified in ['1_2_3', 123, 123.]: + elif cos_powers_modified in ["1_2_3", 123, 123.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) - + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) - + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) + + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) + + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + ) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k1 * const_1_plus_Cos_1_phi_data - + k2 * const_1_minus_Cos_2_phi_data - + k3 * const_1_plus_Cos_3_phi_data + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * const_1_plus_Cos_1_phi_data + + k2 * const_1_minus_Cos_2_phi_data + + k3 * const_1_plus_Cos_3_phi_data + ) ) - elif cos_powers_modified in ['1_2_3_4', 1234, 1234.]: + elif cos_powers_modified in ["1_2_3_4", 1234, 1234.0]: if use_const_1_plus_minus_Cos_x_values_bool is False: - dihedral_energy = 1 / 2 * ( - + k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) - + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) - + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) - + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * (1 + np.cos(1 * scanned_phi * np.pi / 180)) + + k2 * (1 - np.cos(2 * scanned_phi * np.pi / 180)) + + k3 * (1 + np.cos(3 * scanned_phi * np.pi / 180)) + + k4 * (1 - np.cos(4 * scanned_phi * np.pi / 180)) + ) ) elif use_const_1_plus_minus_Cos_x_values_bool is True: - dihedral_energy = 1 / 2 * ( - + k1 * const_1_plus_Cos_1_phi_data - + k2 * const_1_minus_Cos_2_phi_data - + k3 * const_1_plus_Cos_3_phi_data - + k4 * const_1_minus_Cos_4_phi_data + dihedral_energy = ( + 1 + / 2 + * ( + +k1 * const_1_plus_Cos_1_phi_data + + k2 * const_1_minus_Cos_2_phi_data + + k3 * const_1_plus_Cos_3_phi_data + + k4 * const_1_minus_Cos_4_phi_data + ) ) return dihedral_energy + # periodic dihedral function using -def periodic_dihedral_n_1_2_3_4_5(phi_data, - K_0, K_1, K_2, K_3, K_4, K_5, - n_0, n_1, n_2, n_3, n_4, n_5, - d_0, d_1, d_2, d_3, d_4, d_5, - ): +def periodic_dihedral_n_1_2_3_4_5( + phi_data, + K_0, + K_1, + K_2, + K_3, + K_4, + K_5, + n_0, + n_1, + n_2, + n_3, + n_4, + n_5, + d_0, + d_1, + d_2, + d_3, + d_4, + d_5, +): """Periodic or CHARMM style dihedral energy calculation from n=1 to n=5. This is the Periodic or CHARMM style dihedral energy calculation. @@ -839,10 +955,10 @@ def RB_torsion_n_1_2_3_4_5(phi_data, k_0, k_1, k_2, k_3, k_4, k_5): torsion_energy = ( k_0 + k_1 * np.cos(psi_data) - + k_2 * np.cos(psi_data)**2 - + k_3 * np.cos(psi_data)**3 - + k_4 * np.cos(psi_data)**4 - + k_5 * np.cos(psi_data)**5 + + k_2 * np.cos(psi_data) ** 2 + + k_3 * np.cos(psi_data) ** 3 + + k_4 * np.cos(psi_data) ** 4 + + k_5 * np.cos(psi_data) ** 5 ) return torsion_energy @@ -872,18 +988,26 @@ def get_r_squared(data_points, fitted_values): These values are typically 0-1, but can be negative if the intercept constant or other parameters are manually not used in the fitting process. """ - if not isinstance(data_points, (list, type((1, 2)), type(np.array([1])), type(np.ndarray([1])))) \ - or not isinstance(fitted_values, (list, type((1, 2)), type(np.array([1])), type(np.array([1])))): + if not isinstance( + data_points, + (list, type((1, 2)), type(np.array([1])), type(np.ndarray([1]))), + ) or not isinstance( + fitted_values, + (list, type((1, 2)), type(np.array([1])), type(np.array([1]))), + ): raise TypeError( f"ERROR: Both the 'data_points' and 'fitted_values' must be " f"list, tuple, or numpy.array of the same length. The are the following: \n" f"- type(data_points) = {type(data_points)} \n" f"- len(data_points) = {len(data_points)} \n" f"- type(fitted_value) = {type(fitted_values)} \n" - f"- len(fitted_value) = {len(fitted_values)}") + f"- len(fitted_value) = {len(fitted_values)}" + ) for r_i in range(0, len(data_points)): - if not isinstance(data_points[r_i], (float, int)) or not isinstance(fitted_values[r_i], (float, int)): + if not isinstance(data_points[r_i], (float, int)) or not isinstance( + fitted_values[r_i], (float, int) + ): raise TypeError( f"ERROR: The 'data_points' or 'fitted_values' lists do not contain all floats or integers." ) @@ -891,14 +1015,8 @@ def get_r_squared(data_points, fitted_values): rss = 0 tss = 0 for iter_i, value_i in enumerate(data_points): - rss += ( - data_points[iter_i] - - fitted_values[iter_i] - ) ** 2 - tss += ( - data_points[iter_i] - - np.average(data_points) - ) ** 2 + rss += (data_points[iter_i] - fitted_values[iter_i]) ** 2 + tss += (data_points[iter_i] - np.average(data_points)) ** 2 r_squared_0_to_1 = 1 - rss / tss