Skip to content

Commit

Permalink
Merge pull request #349 from UCL-CCS/feature-ligq-in-ligand
Browse files Browse the repository at this point in the history
Taking net-q from MOL2 files.
  • Loading branch information
bieniekmateusz authored Feb 14, 2025
2 parents 9600781 + fe3d50f commit d17dfd3
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions ties/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,14 @@ def ligand_net_charge(self):
:return:
"""
if self._ligand_net_charge is None:
logger.warning(f'Ligand net charge not provided (-nc) by the user. Assuming 0. ')
self._ligand_net_charge = 0
if self._ligands_contain_q:
net_q = self._get_first_ligand_net_q()
logger.info(f"Using the first ligand's net q = {net_q} "
f"(from partial charges)")
self._ligand_net_charge = net_q
else:
logger.warning('Ligand net charge not provided (-nc). Assuming 0. ')
self._ligand_net_charge = 0

return self._ligand_net_charge

Expand Down Expand Up @@ -448,6 +454,10 @@ def use_original_coor(self, boolean):
self._use_original_coor = boolean

def _guess_ligands_contain_q(self):
"""
Checks if the first .mol2 file contains charges.
:return:
"""
# if all ligands are .mol2, then charges are provided
if all(l.suffix.lower() == '.mol2' for l in self.ligand_files):
# if all atoms have q = 0 that means they're a placeholder
Expand All @@ -460,6 +470,16 @@ def _guess_ligands_contain_q(self):

return False

def _get_first_ligand_net_q(self):
"""
:return: Returns the net charge from the parmed file with partial charges.
"""

# if all atoms have q = 0 that means they're a placeholder
u = parmed.load_file(str(list(self.ligand_files)[0]), structure=True)
net_q = sum(a.charge == 0 for a in u.atoms)
return net_q

@property
def ligands_contain_q(self):
"""
Expand All @@ -472,10 +492,6 @@ def ligands_contain_q(self):
:rtype: bool
"""

if self._ligand_files is None:
logger.warning('Whether ligands contain charges has not been configured. Guessing. ')
self._ligand_files = self._guess_ligands_contain_q()

# does the file type contain charges?
ligand_ext = set(l.suffix.lower() for l in self.ligand_files).pop()
if self._ligands_contain_q is True:
Expand All @@ -492,7 +508,7 @@ def ligands_contain_q(self):
if ligand_ext in {'.mol2', '.ac', '.prep'}:
# if all charges are 0, then recompute
self._ligands_contain_q = self._guess_ligands_contain_q()
logger.info(f'Existing atom charges detected (filetype .ac/.mol2). ')
logger.info(f'Existing atom charges detected (filetype .ac/.mol2)')
elif ligand_ext == '.pdb':
self._ligands_contain_q = False
logger.debug('Assuming that charges are not provided in the given .pdb ligand files. ')
Expand Down

0 comments on commit d17dfd3

Please # to comment.