ionerdss.nerdss_simulation package

Submodules

ionerdss.nerdss_simulation.simulation module

class ionerdss.nerdss_simulation.simulation.Simulation(work_dir: str)[source]

Bases: object

Class for handling NERDSS simulation configurations and running simulations.

work_dir

The working directory for the simulation.

Type:

str

add_interface_state(mol_name: str, interface_name: str, states: List[str]) None[source]

Adds states to a specified interface of a molecule.

Parameters:
  • mol_name (str) – The name of the molecule.

  • interface_name (str) – The name of the interface.

  • states (List[str]) – List of single-character state names.

Raises:
  • FileNotFoundError – If the molecule file does not exist.

  • ValueError – If no valid states are provided.

calculate_progress_percentage(sim_subdir: str) int[source]

Calculates the progress percentage of a running simulation.

Parameters:

sim_subdir (str) – The directory of the simulation.

install_nerdss(nerdss_path: str | None = None) None[source]

Installs the NERDSS package.

Parameters:

nerdss_path (str) – The path to install NERDSS. If None, uses the current directory.

modify_inp_file(modifications: Dict[str, Any], filename: str = 'parms.inp') None[source]

Modifies the parameters of the parms.inp file. If isSphere and sphereR are provided, removes the WaterBox line and adds the new lines accordingly. If WaterBox is provided, removes isSphere and sphereR if they exist.

Parameters:
  • modifications (Dict[str, Any]) – A dictionary containing parameter modifications.

  • filename (str) – The name of the input file to modify. Defaults to “parms.inp”.

modify_mol_file(mol_name: str, modifications: Dict[str, Any]) None[source]

Modifies the parameters of an existing .mol file.

Parameters:
  • mol_name (str) – The name of the molecule to modify.

  • modifications (Dict[str, Any]) – A dictionary containing parameter modifications.

Raises:

FileNotFoundError – If the specified molecule file does not exist.

print_inp_file(file_name: str = 'parms.inp') None[source]

Prints the contents of the parms.inp file.

Parameters:

file_name (str) – The name of the input file to print. Defaults to “parms.inp”.

print_mol_parameters(mol_name: str) None[source]

Prints all parameters of a given .mol file.

Parameters:

mol_name (str) – The name of the molecule to display.

Raises:

FileNotFoundError – If the specified molecule file does not exist.

pull_mol_file_information(file: str)[source]

Extracts molecular configuration information from a .mol-style input file into a dictionary.

Parameters:

filestr

Path to the input .mol file containing molecular relationship and configuration information.

Returns:

dict

A dictionary where keys are molecular attribute names (e.g., “mass”, “COM”, “D” for example) and values are either strings or lists of floats depending on the format in the file.

Example:

Given a section of a .mol file, the output might look like: {

“mass”: “1.0”, “COM”: [0.0, 0.0, 1.0], “D” = [13.0, 13.0, 13.0]

}

pull_parameter_file_information(file: str)[source]

Parses a simulation input file and extracts parameter, boundary, and molecule information into a dictionary.

Parameters:

filestr

Path to the input file containing the simulation parameters and configuration data.

Returns:

dict

A dictionary containing key-value pairs from the parameters, boundaries, and molecules blocks. - Keys are parameter names (e.g., “dt”, “runtime”). - Values are strings, floats, or lists of floats depending on the format of the line in the file.

Example:

Given an input file, the function might return: {

“nItr”: “10000”, “timeStep”: “0.1”, ‘WaterBox’ = [100, 100, 100],

}

pull_reaction_information(file: str)[source]

Extracts reaction information from a given input file and returns it as a dictionary.

The function parses a file (e.g., “parms.inp”) to extract details about reactions within a specific block labeled by “start reactions” and “end reactions”. For each reaction, the function captures relevant information and organizes it into a dictionary, where each key corresponds to a reaction equation (e.g., “A <-> B”) and its associated parameters.

Reaction details are stored as nested dictionaries, with the reaction equation as the outer key, and each parameter as an inner key-value pair.

Parameters:

filestr

The path to the input file containing the reaction information.

Returns:

dict

A dictionary where each key is a reaction equation (e.g., “A <-> B”) and the value is another dictionary containing parameters and values associated with that reaction. The parameters may include things like exclusion conditions and numerical values for reaction conditions.

Example:

Given an input file containing reaction data, the function will return a dictionary like: {

“A <-> B”: {

“norm1”: [1.0, 2.0, 3.0], “sigma”: “1.20302012”

}, “C -> D”: {

“onRate”: “0”

}

}

Notes:

  • The function assumes the input file contains structured reaction information in blocks marked by “start reactions” and “end reactions”.

  • Each reaction line may contain additional parameters, which are processed as key-value pairs.

  • Lines with “exclude” are treated specially, storing them in the dictionary under the respective reaction.

run_new_simulations(sim_indices: List[int] | None = None, sim_dir: str | None = None, nerdss_dir: str | None = None, parallel: bool = False, coordinate: bool = False, progress: bool = True, verbose=True) None[source]

Runs NERDSS simulations based on the given parameters.

Parameters:
  • sim_indices (List[int], optional) – List of simulation indices to run. If None, runs one simulation with index = 1.

  • sim_dir (str, optional) – Directory where simulation results should be stored. Defaults to self.work_dir/nerdss_output.

  • nerdss_dir (str, optional) – Directory where NERDSS is installed. Defaults to self.work_dir/NERDSS.

  • parallel (bool, optional) – Whether to run simulations in parallel. Defaults to False.

Notes

FIXME: Doesn’t work on Fedora OS using Jupyter notebook. Doesn’t test on other OS. Doesn’t test using Python script.

run_restart_simulations(sim_indices: List[int] | None = None, sim_dir: str | None = None, nerdss_dir: str | None = None, restart_from: str = '', restart_sim_name: str = 'restart_sim', parallel: bool = False) None[source]

Runs NERDSS simulations from a restart file.

Parameters:
  • sim_indices (List[int], optional) – List of simulation indices to restart. If None, restarts one simulation with index = 1.

  • sim_dir (str, optional) – Directory where restarted simulation results should be stored. Defaults to self.work_dir/nerdss_output.

  • nerdss_dir (str, optional) – Directory where NERDSS is installed. Defaults to self.work_dir/NERDSS.

  • restart_from (str) – Path to the directory containing the restart file.

  • restart_sim_name (str) – Name of the folder where restarted simulations will be stored.

  • parallel (bool, optional) – Whether to run simulations in parallel. Defaults to False.

Module contents

class ionerdss.nerdss_simulation.Simulation(work_dir: str)[source]

Bases: object

Class for handling NERDSS simulation configurations and running simulations.

work_dir

The working directory for the simulation.

Type:

str

add_interface_state(mol_name: str, interface_name: str, states: List[str]) None[source]

Adds states to a specified interface of a molecule.

Parameters:
  • mol_name (str) – The name of the molecule.

  • interface_name (str) – The name of the interface.

  • states (List[str]) – List of single-character state names.

Raises:
  • FileNotFoundError – If the molecule file does not exist.

  • ValueError – If no valid states are provided.

calculate_progress_percentage(sim_subdir: str) int[source]

Calculates the progress percentage of a running simulation.

Parameters:

sim_subdir (str) – The directory of the simulation.

install_nerdss(nerdss_path: str | None = None) None[source]

Installs the NERDSS package.

Parameters:

nerdss_path (str) – The path to install NERDSS. If None, uses the current directory.

modify_inp_file(modifications: Dict[str, Any], filename: str = 'parms.inp') None[source]

Modifies the parameters of the parms.inp file. If isSphere and sphereR are provided, removes the WaterBox line and adds the new lines accordingly. If WaterBox is provided, removes isSphere and sphereR if they exist.

Parameters:
  • modifications (Dict[str, Any]) – A dictionary containing parameter modifications.

  • filename (str) – The name of the input file to modify. Defaults to “parms.inp”.

modify_mol_file(mol_name: str, modifications: Dict[str, Any]) None[source]

Modifies the parameters of an existing .mol file.

Parameters:
  • mol_name (str) – The name of the molecule to modify.

  • modifications (Dict[str, Any]) – A dictionary containing parameter modifications.

Raises:

FileNotFoundError – If the specified molecule file does not exist.

print_inp_file(file_name: str = 'parms.inp') None[source]

Prints the contents of the parms.inp file.

Parameters:

file_name (str) – The name of the input file to print. Defaults to “parms.inp”.

print_mol_parameters(mol_name: str) None[source]

Prints all parameters of a given .mol file.

Parameters:

mol_name (str) – The name of the molecule to display.

Raises:

FileNotFoundError – If the specified molecule file does not exist.

pull_mol_file_information(file: str)[source]

Extracts molecular configuration information from a .mol-style input file into a dictionary.

Parameters:

filestr

Path to the input .mol file containing molecular relationship and configuration information.

Returns:

dict

A dictionary where keys are molecular attribute names (e.g., “mass”, “COM”, “D” for example) and values are either strings or lists of floats depending on the format in the file.

Example:

Given a section of a .mol file, the output might look like: {

“mass”: “1.0”, “COM”: [0.0, 0.0, 1.0], “D” = [13.0, 13.0, 13.0]

}

pull_parameter_file_information(file: str)[source]

Parses a simulation input file and extracts parameter, boundary, and molecule information into a dictionary.

Parameters:

filestr

Path to the input file containing the simulation parameters and configuration data.

Returns:

dict

A dictionary containing key-value pairs from the parameters, boundaries, and molecules blocks. - Keys are parameter names (e.g., “dt”, “runtime”). - Values are strings, floats, or lists of floats depending on the format of the line in the file.

Example:

Given an input file, the function might return: {

“nItr”: “10000”, “timeStep”: “0.1”, ‘WaterBox’ = [100, 100, 100],

}

pull_reaction_information(file: str)[source]

Extracts reaction information from a given input file and returns it as a dictionary.

The function parses a file (e.g., “parms.inp”) to extract details about reactions within a specific block labeled by “start reactions” and “end reactions”. For each reaction, the function captures relevant information and organizes it into a dictionary, where each key corresponds to a reaction equation (e.g., “A <-> B”) and its associated parameters.

Reaction details are stored as nested dictionaries, with the reaction equation as the outer key, and each parameter as an inner key-value pair.

Parameters:

filestr

The path to the input file containing the reaction information.

Returns:

dict

A dictionary where each key is a reaction equation (e.g., “A <-> B”) and the value is another dictionary containing parameters and values associated with that reaction. The parameters may include things like exclusion conditions and numerical values for reaction conditions.

Example:

Given an input file containing reaction data, the function will return a dictionary like: {

“A <-> B”: {

“norm1”: [1.0, 2.0, 3.0], “sigma”: “1.20302012”

}, “C -> D”: {

“onRate”: “0”

}

}

Notes:

  • The function assumes the input file contains structured reaction information in blocks marked by “start reactions” and “end reactions”.

  • Each reaction line may contain additional parameters, which are processed as key-value pairs.

  • Lines with “exclude” are treated specially, storing them in the dictionary under the respective reaction.

run_new_simulations(sim_indices: List[int] | None = None, sim_dir: str | None = None, nerdss_dir: str | None = None, parallel: bool = False, coordinate: bool = False, progress: bool = True, verbose=True) None[source]

Runs NERDSS simulations based on the given parameters.

Parameters:
  • sim_indices (List[int], optional) – List of simulation indices to run. If None, runs one simulation with index = 1.

  • sim_dir (str, optional) – Directory where simulation results should be stored. Defaults to self.work_dir/nerdss_output.

  • nerdss_dir (str, optional) – Directory where NERDSS is installed. Defaults to self.work_dir/NERDSS.

  • parallel (bool, optional) – Whether to run simulations in parallel. Defaults to False.

Notes

FIXME: Doesn’t work on Fedora OS using Jupyter notebook. Doesn’t test on other OS. Doesn’t test using Python script.

run_restart_simulations(sim_indices: List[int] | None = None, sim_dir: str | None = None, nerdss_dir: str | None = None, restart_from: str = '', restart_sim_name: str = 'restart_sim', parallel: bool = False) None[source]

Runs NERDSS simulations from a restart file.

Parameters:
  • sim_indices (List[int], optional) – List of simulation indices to restart. If None, restarts one simulation with index = 1.

  • sim_dir (str, optional) – Directory where restarted simulation results should be stored. Defaults to self.work_dir/nerdss_output.

  • nerdss_dir (str, optional) – Directory where NERDSS is installed. Defaults to self.work_dir/NERDSS.

  • restart_from (str) – Path to the directory containing the restart file.

  • restart_sim_name (str) – Name of the folder where restarted simulations will be stored.

  • parallel (bool, optional) – Whether to run simulations in parallel. Defaults to False.