4.2. ligandparam.stages.charge

class ligandparam.stages.charge.StageNormalizeCharge(name, orig_mol2=None, new_mol2=None, precision=0.0001, inputoptions=None)[source]

Bases: AbstractStage

This class normalizes the charges to the 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:
  • name (str) – The name of the stage

  • base_cls (Ligand) – The base class of the ligand

  • orig_mol2 (str) – The original mol2 file

  • new_mol2 (str) – The new mol2 file

  • precision (float) – The precision of the charge normalization

Raises:
  • ValueError – If the original mol2 file is not provided

  • ValueError – If the new mol2 file is not provided

Methods

check_charge(charges)

This function checks the total charge and the charge difference.

list_files_in_directory(directory)

List all the files in a directory.

normalize(charges, charge_difference)

This function normalizes the charges to the net charge.

print_charge_differences(names, ...)

This function prints the charge differences between the original and new charges.

print_docs()

Print the documentation for the stage.

append_stage

clean

execute

_abc_impl = <_abc._abc_data object>
_append_stage(stage: AbstractStage) AbstractStage[source]
_clean()[source]
_execute(dry_run=False)[source]

This class normalizes the charges to the net charge.

This function 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, starting with the largest charges.

Raises:
  • ValueError – If the charge normalization fails

  • TODO – Check what happens when netcharge is nonzero:

  • TODO – Check what happens when charge difference is larger than the number of atoms:

check_charge(charges)[source]

This function checks the total charge and the charge difference.

Parameters:

charges (np.array) – The charges

Returns:

  • total_charge (float) – The total charge

  • charge_difference (float) – The charge difference

normalize(charges, charge_difference)[source]

This function normalizes the charges to the net charge.

Parameters:
  • charges (np.array) – The charges

  • charge_difference (float) – The charge difference

Returns:

charges – The normalized charges

Return type:

np.array

print_charge_differences(names, orig_charges, new_charges)[source]

This function prints the charge differences between the original and new charges.

Parameters:
  • names (np.array) – The atom names

  • orig_charges (np.array) – The original charges

  • new_charges (np.array) – The new charges

class ligandparam.stages.charge.StageUpdateCharge(name, orig_mol2=None, new_mol2=None, charge_source='multistate', charge_column=None, inputoptions=None)[source]

Bases: AbstractStage

This class creates a new mol2 file with updated charges.

Parameters:
  • name (str) – The name of the stage

  • base_cls (Ligand) – The base class of the ligand

  • orig_mol2 (str) – The original mol2 file

  • new_mol2 (str) – The new mol2 file

  • charge_source (str) – The source of the charges

  • charge_column (int) – The column of the charges

Methods

list_files_in_directory(directory)

List all the files in a directory.

print_docs()

Print the documentation for the stage.

append_stage

clean

execute

_abc_impl = <_abc._abc_data object>
_append_stage(stage: AbstractStage) AbstractStage[source]
_clean()[source]
_execute(dry_run=False)[source]

Execute StageUpdateCharge to update charges in a mol2 file from a charge source.

This stage will update the charges in a mol2 file from a charge source file. This could be a respfit.out file, or any other file with charges stored in a column. The column number is specified in the charge_column variable when the stage is initialized.

Parameters:

dry_run (bool, optional) – If True, the stage will not be executed, but the function will print the commands that would

Raises:
  • FileNotFoundError – If the charge source file is not found

  • ValueError – If the number of charges does not match the number of atoms