4.2. ligandparam.stages.charge
- class ligandparam.stages.charge.StageNormalizeCharge(stage_name: str, main_input: Path | str, cwd: Path | str, *args, **kwargs)[source]
Bases:
AbstractStageNormalize the charges in a mol2 file to the specified net charge.
This class works by calculating the charge difference, and then normalizing the charges based on the overall precision that you select, by adjusting each atom charge by the precision until the charge difference is zero.
- Parameters:
stage_name (str) – The name of the stage.
main_input (Union[Path, str]) – Path to the input mol2 file.
cwd (Union[Path, str]) – Current working directory.
out_mol2 (str) – Path to the output mol2 file.
atom_type (str, optional) – Atom type (default: ‘gaff2’).
net_charge (float, optional) – Net charge for the molecule (default: 0.0).
precision (float, optional) – Precision for charge normalization (default: 0.0001).
- in_mol2
Path to the input mol2 file.
- Type:
Path
- out_mol2
Path to the output mol2 file.
- Type:
Path
- tmp_mol2
Path to the temporary mol2 file.
- Type:
Path
- atom_type
Atom type.
- Type:
str
- net_charge
Net charge for the molecule.
- Type:
float
- precision
Precision for charge normalization.
- Type:
float
- decimals
Number of decimals for rounding charges.
- Type:
int
Methods
add_required(filename)Add a required file to the stage.
append_stage(stage)Append a stage to the current stage.
check_charge(charges)Check the total charge and the charge difference.
clean()Clean up the stage.
execute([dry_run, nproc, mem])Execute the charge normalization stage.
list_files_in_directory(directory)List all the files in a directory.
normalize(charges, charge_difference)Normalize the charges to the net charge.
Initialize the AbstractStage.
- Parameters:
stage_name (str) – The name of the stage.
main_input (Union[Path, str]) – The main input file for the stage.
cwd (Union[Path, str]) – The current working directory for the stage.
Methods
add_required(filename)Add a required file to the stage.
append_stage(stage)Append a stage to the current stage.
check_charge(charges)Check the total charge and the charge difference.
clean()Clean up the stage.
execute([dry_run, nproc, mem])Execute the charge normalization stage.
list_files_in_directory(directory)List all the files in a directory.
normalize(charges, charge_difference)Normalize the charges to the net charge.
- check_charge(charges)[source]
Check the total charge and the charge difference.
- Parameters:
charges (np.ndarray) – Array of atomic charges.
- Returns:
- chargesnp.ndarray
Rounded charges.
- total_chargefloat
The total charge.
- charge_differencefloat
The charge difference.
- Return type:
tuple
- execute(dry_run=False, nproc: int | None = None, mem: int | None = None) Any[source]
Execute the charge normalization stage.
- Parameters:
dry_run (bool, optional) – If True, the stage will not be executed, but the function will print the commands that would be run.
nproc (int, optional) – Number of processors to use.
mem (int, optional) – Amount of memory to use (in GB).
- Raises:
ValueError – If the charge normalization fails.
Notes
TODO: Check what happens when netcharge is nonzero. TODO: Check what happens when charge difference is larger than the number of atoms.
- class ligandparam.stages.charge.StageUpdateCharge(stage_name: str, main_input: Path | str, cwd: Path | str, *args, **kwargs)[source]
Bases:
AbstractStageCreate a new mol2 file with updated charges.
- Parameters:
stage_name (str) – The name of the stage.
main_input (Union[Path, str]) – Path to the input mol2 file.
cwd (Union[Path, str]) – Current working directory.
charge_source (str) – Path to the file containing charges.
charge_column (int, optional) – Column index in charge_source to use for charges (default: 3).
out_mol2 (str) – Path to the output mol2 file.
net_charge (float, optional) – Net charge for the molecule (default: 0.0).
atom_type (str, optional) – Atom type (default: ‘gaff2’).
- in_mol2
Path to the input mol2 file.
- Type:
Path
- charge_source
Path to the file containing charges.
- Type:
str
- charge_column
Column index in charge_source to use for charges.
- Type:
int
- out_mol2
Path to the output mol2 file.
- Type:
Path
- tmp_mol2
Path to the temporary mol2 file.
- Type:
Path
- net_charge
Net charge for the molecule.
- Type:
float
- atom_type
Atom type.
- Type:
str
Methods
add_required(filename)Add a required file to the stage.
append_stage(stage)Append a stage to the current stage.
clean()Clean up the stage.
execute([dry_run, nproc, mem])Execute the stage.
list_files_in_directory(directory)List all the files in a directory.
Initialize the AbstractStage.
- Parameters:
stage_name (str) – The name of the stage.
main_input (Union[Path, str]) – The main input file for the stage.
cwd (Union[Path, str]) – The current working directory for the stage.
Methods
add_required(filename)Add a required file to the stage.
append_stage(stage)Append a stage to the current stage.
clean()Clean up the stage.
execute([dry_run, nproc, mem])Execute the stage.
list_files_in_directory(directory)List all the files in a directory.
- execute(dry_run=False, nproc: int | None = None, mem: int | None = None) Any[source]
Execute the stage.
- Parameters:
dry_run (bool, optional) – Whether to execute in dry-run mode (default is False).
nproc (int, optional) – The number of processors to use (default is None).
mem (int, optional) – The amount of memory to use (in GB, default is None).
- Returns:
The result of the execution.
- Return type:
Any