Skip to content

Commit

Permalink
check bad charges
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomart committed Jul 28, 2023
1 parent 6e839ce commit 6ee171c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion meeko/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import sys
import json
import math

import numpy as np
from rdkit import Chem
Expand Down Expand Up @@ -102,7 +103,7 @@ def _walk_graph_recursive(cls, setup, node, data, edge_start=0, first=False):
return data

@classmethod
def write_string(cls, setup, add_index_map=False, remove_smiles=False):
def write_string(cls, setup, add_index_map=False, remove_smiles=False, bad_charge_ok=False):
"""Output a PDBQT file as a string.
Args:
Expand All @@ -122,9 +123,15 @@ def write_string(cls, setup, add_index_map=False, remove_smiles=False):
success = False

for idx, atom_type in setup.atom_type.items():
if setup.atom_ignore[idx]:
continue
if atom_type is None:
error_msg += 'atom number %d has None type, mol name: %s\n' % (idx, setup.get_mol_name())
success = False
c = setup.charge[idx]
if not bad_charge_ok and (type(c) != float and type(c) != int or math.isnan(c) or math.isinf(c)):
error_msg += 'atom number %d has non finite charge, mol name: %s, charge: %s\n' % (idx, setup.get_mol_name(), str(c))
success = False

if not success:
pdbqt_string = ""
Expand Down
5 changes: 3 additions & 2 deletions scripts/mk_prepare_ligand.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def cmd_lineparser():
config_group.add_argument("-aa", "--add_atom_types", dest="add_atom_types_json",
action="append", help="Additional atom types to assign (JSON formated)", metavar="[{'smarts': '<smarts pattern>', 'atype': ',atomtype name>'}, {'smarts': '<smarts pattern>', 'atype': ',atomtype name>'}]")
config_group.add_argument("--double_bond_penalty", help="penalty > 100 prevents breaking double bonds", type=int)
config_group.add_argument("--bad_charge_ok", help="NaN and Inf charges allowed in PDBQT", action="store_true")
config_group.add_argument("--add_index_map", dest="add_index_map",
action="store_true", help="write map of atom indices from input to pdbqt")
config_group.add_argument("--remove_smiles", dest="remove_smiles",
Expand Down Expand Up @@ -337,7 +338,7 @@ def get_suffixes(molsetups):
res, chain, num = cov_lig.res_id
suffixes = output.get_suffixes(molsetups)
for molsetup, suffix in zip(molsetups, suffixes):
pdbqt_string, success, error_msg = PDBQTWriterLegacy.write_string(molsetup)
pdbqt_string, success, error_msg = PDBQTWriterLegacy.write_string(molsetup, bad_charge_ok=args.bad_charge_ok)
if success:
pdbqt_string = PDBQTWriterLegacy.adapt_pdbqt_for_autodock4_flexres(pdbqt_string, res, chain, num)
name = molsetup.name
Expand All @@ -351,7 +352,7 @@ def get_suffixes(molsetups):
molsetups = preparator.prepare(mol)
suffixes = output.get_suffixes(molsetups)
for molsetup, suffix in zip(molsetups, suffixes):
pdbqt_string, success, error_msg = PDBQTWriterLegacy.write_string(molsetup)
pdbqt_string, success, error_msg = PDBQTWriterLegacy.write_string(molsetup, bad_charge_ok=args.bad_charge_ok)
if success:
name = molsetup.name
output(pdbqt_string, name, (suffix,))
Expand Down

0 comments on commit 6ee171c

Please sign in to comment.