Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing multiple solutions to be returned in order to use weights for RMSD/overlap #325

Merged
merged 9 commits into from
Aug 19, 2023
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Install ties
shell: bash -l {0}
run: |
python -m pip install . --no-deps -v
python -m pip install --no-deps .

- name: Install pytest
shell: bash -l {0}
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ channels:
- defaults

dependencies:
- conda-forge::ambertools >=20.0
- conda-forge::ambertools >=21.0
- ties_md
- numpy <=1.23.5
- numpy
- cython
- setuptools
- matplotlib
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
22 changes: 5 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from setuptools import setup, find_packages
from distutils.extension import Extension
from pathlib import Path

import numpy

# get the information about numpy header files
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
import numpy
numpy.get_include()
except ModuleNotFoundError:
pass

# handle cython modules: pyqcprot module for the rotation matrix
try:
Expand All @@ -22,7 +19,7 @@
print (f'use_cython: {use_cython}')

ext_modules = [Extension("ties/pyqcprot_ext/pyqcprot", [f"ties/pyqcprot_ext/pyqcprot.{'pyx' if use_cython else 'c'}"],
include_dirs=[numpy_include],
include_dirs=[],
extra_compile_args=["-O3","-ffast-math"])]

setup(
Expand All @@ -35,15 +32,6 @@
author_email='[email protected]',
packages=find_packages(),
include_package_data=True,
install_requires=[
'numpy',
'cython',
'setuptools',
'matplotlib',
'networkx',
'dimod',
'tabulate',
'dwave-networkx'],
entry_points={
'console_scripts': [
'ties = ties:cli.command_line_script'
Expand Down
16 changes: 11 additions & 5 deletions ties/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ def command_line_script():
'If more than 2 ligands are provided, '
'Lead Optimisation Mapping (TIES MAP) will be used.')
parser.add_argument('-dir', '--ties-output-dir', metavar='directory', dest='workdir',
type=pathlib.Path, required=False,
help='If not provided, "ties20" directory will be created in the current directory. ')
type=pathlib.Path, required=False, default="ties",
help='The destination directory for the output. Default: "ties".')
parser.add_argument('-nc', '--ligand-net-charge', metavar='integer', dest='ligand_net_charge',
type=int, required=False,
help='An integer representing the net charge of each ligand. '
'All ligands must have the same charge.')
'All ligands must have the same charge. Default: 0.1e.')
parser.add_argument('-p', '--protein', metavar='file', dest='protein',
type=ArgparseChecker.existing_file, required=False,
help='The protein file')
help='The protein file. Not necessary. ')
parser.add_argument('-qtol', '--q-pair-tolerance', metavar='decimal', dest='atom_pair_q_atol',
type=float, required=False, default=0.1,
type=float, required=False,
help='The maximum difference in charge between any two paired atoms (electron unit). '
'Default 0.1e')
parser.add_argument('-netqtol', '--q-net-tolerance', metavar='decimal', dest='net_charge_threshold',
Expand Down Expand Up @@ -133,6 +133,12 @@ def command_line_script():
parser.add_argument('-elements', '--compare-elements', metavar='boolean', dest='use_element',
type=ArgparseChecker.str2bool, required=False, default=False,
help='Ignore the specific atom types in the superimposition. Use only the elements. ')
parser.add_argument('-weights', '--mcs-rmsd-weights', metavar='str', dest='weights_ratio',
type=ArgparseChecker.ratio, required=False,
help='The weights for the weighted sum of 1) MCS overlap size to 2) RMSD '
'when coordinates are used for selection of the best structure. '
'Default it is "1:1" for "MCS:RMSD". '
'MCS is defined (1 - MCS fraction), so lower value is better.')

# initialise the config class
args = parser.parse_args()
Expand Down
9 changes: 7 additions & 2 deletions ties/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(self, **kwargs):
# use only the element in the superimposition rather than the specific atom type
self._use_element = False
self._use_element_in_superimposition = True
# weights in choosing the best MCS, the weighted sum of "(1 - MCS fraction) and RMSD".
self.weights = [1, 0.5]

# coordinates
self._align_molecules_using_mcs = False
Expand Down Expand Up @@ -82,8 +84,7 @@ def __init__(self, **kwargs):
self.uses_cmd = False

# assign all the initial configuration values
for key, value in kwargs.items():
setattr(self, key, value)
self.set_configs(**kwargs)

@property
def workdir(self):
Expand Down Expand Up @@ -897,4 +898,8 @@ def get_serializable(self):
def set_configs(self, **kwargs):
# set all the configs one by one
for k,v in kwargs.items():
# skip None values, these come from the command line
if v is None:
continue

setattr(self, k, v)
7 changes: 7 additions & 0 deletions ties/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def str2bool(v):
else:
raise argparse.ArgumentTypeError('Boolean value expected.')

@staticmethod
def ratio(v):
if ':' not in v:
argparse.ArgumentTypeError('The ratio has to be separated by ":".')
mcs, rmsd = v.split(':')
return [float(mcs), float(rmsd)]

@staticmethod
def existing_file(v):
# check ligand arguments
Expand Down
14 changes: 7 additions & 7 deletions ties/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def superimpose(self, **kwargs):
print('Starting nodes will be used:', starting_node_pairs)

# fixme - simplify to only take the ParmEd as input
suptops = superimpose_topologies(ligand1_nodes.values(), ligand2_nodes.values(),
suptop = superimpose_topologies(ligand1_nodes.values(), ligand2_nodes.values(),
disjoint_components=self.config.allow_disjoint_components,
net_charge_filter=True,
pair_charge_atol=self.config.atom_pair_q_atol,
Expand All @@ -173,16 +173,16 @@ def superimpose(self, **kwargs):
force_mismatch=new_mismatch_names,
starting_node_pairs=starting_node_pairs,
parmed_ligA=parmed_ligA, parmed_ligZ=parmed_ligZ,
starting_pair_seed=self.config.superimposition_starting_pair)
starting_pair_seed=self.config.superimposition_starting_pair,
config=self.config)

assert len(suptops) == 1
self.set_suptop(suptops[0], parmed_ligA, parmed_ligZ)
self.set_suptop(suptop, parmed_ligA, parmed_ligZ)
# attach the used config to the suptop
suptops[0].config = self.config
suptop.config = self.config
# attach the morph to the suptop
suptops[0].morph = self
suptop.morph = self

return suptops[0]
return suptop

def set_suptop(self, suptop, parmed_ligA, parmed_ligZ):
"""
Expand Down
Loading