Skip to content

Commit

Permalink
Fixed error in importing cosolvkit with python3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nbruciaferri committed May 14, 2024
1 parent 6bc8a15 commit 2e04017
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 483 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![License: LGPL v2.1](https://img.shields.io/badge/License-LGPL_v2.1-green.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) [![PyPI - Version](https://img.shields.io/pypi/v/cosolvkit)](https://pypi.org/project/cosolvkit/0.4.4/) [![Powered by RDKit](https://img.shields.io/badge/Powered%20by-RDKit-3838ff.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAFVBMVEXc3NwUFP8UPP9kZP+MjP+0tP////9ZXZotAAAAAXRSTlMAQObYZgAAAAFiS0dEBmFmuH0AAAAHdElNRQfmAwsPGi+MyC9RAAAAQElEQVQI12NgQABGQUEBMENISUkRLKBsbGwEEhIyBgJFsICLC0iIUdnExcUZwnANQWfApKCK4doRBsKtQFgKAQC5Ww1JEHSEkAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wMy0xMVQxNToyNjo0NyswMDowMDzr2J4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDMtMTFUMTU6MjY6NDcrMDA6MDBNtmAiAAAAAElFTkSuQmCC)](https://www.rdkit.org/)
[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![License: LGPL v2.1](https://img.shields.io/badge/License-LGPL_v2.1-green.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) [![PyPI - Version](https://img.shields.io/pypi/v/cosolvkit)](https://pypi.org/project/cosolvkit/0.4.5/) [![Powered by RDKit](https://img.shields.io/badge/Powered%20by-RDKit-3838ff.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAFVBMVEXc3NwUFP8UPP9kZP+MjP+0tP////9ZXZotAAAAAXRSTlMAQObYZgAAAAFiS0dEBmFmuH0AAAAHdElNRQfmAwsPGi+MyC9RAAAAQElEQVQI12NgQABGQUEBMENISUkRLKBsbGwEEhIyBgJFsICLC0iIUdnExcUZwnANQWfApKCK4doRBsKtQFgKAQC5Ww1JEHSEkAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wMy0xMVQxNToyNjo0NyswMDowMDzr2J4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDMtMTFUMTU6MjY6NDcrMDA6MDBNtmAiAAAAAElFTkSuQmCC)](https://www.rdkit.org/)
[![Documentation Status](https://readthedocs.org/projects/cosolvkit/badge/?version=latest)](https://cosolvkit.readthedocs.io/en/latest/?badge=latest)


Expand Down
39 changes: 20 additions & 19 deletions cosolvkit/cosolvent_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import io
from collections import defaultdict
from typing import Union
import numpy as np
from scipy import spatial
from scipy.stats import qmc
Expand Down Expand Up @@ -635,8 +636,8 @@ def _create_system(self, forcefield: app.forcefield, topology: app.Topology) ->
def add_cosolvents(self,
cosolvents: dict,
vectors: tuple[Vec3, Vec3, Vec3],
lowerBound: openmmunit.Quantity | Vec3,
upperBound: openmmunit.Quantity | Vec3,
lowerBound: Union[openmmunit.Quantity, Vec3],
upperBound: Union[openmmunit.Quantity, Vec3],
receptor_positions: list) -> dict:
"""This function adds the desired number of cosolvent molecules using the halton sequence
to generate random uniformly distributed points inside the grid where to place the cosolvent molecules.
Expand All @@ -648,9 +649,9 @@ def add_cosolvents(self,
:param vectors: vectors defining the simulation box
:type vectors: tuple[openmm.Vec3, openmm.Vec3, openmm.Vec3]
:param lowerBound: lower bound of the simulation box
:type lowerBound: openmm.unit.Quantity | Vec3
:type lowerBound: Union[openmm.unit.Quantity, Vec3]
:param upperBound: upper bound of the simulation box
:type upperBound: openmm.unit.Quantity | Vec3
:type upperBound: [openmm.unit.Quantity, Vec3]
:param receptor_positions: list of 3D coordinates of the receptor
:type receptor_positions: list
:return: keys are cosolvent molecules and values are 3D coordinates of the newly added cosolvent molecules
Expand Down Expand Up @@ -758,8 +759,8 @@ def accept_reject(self,
halton: list,
kdtree: spatial.cKDTree,
valid_ids: list,
lowerBound: openmmunit.Quantity | Vec3,
upperBound: openmmunit.Quantity | Vec3,
lowerBound: Union[openmmunit.Quantity, Vec3],
upperBound: Union[openmmunit.Quantity, Vec3],
protein_kdtree: spatial.cKDTree) -> tuple[np.ndarray, list]:
"""Accepts or reject the halton move. A random halton point is selected and checked, if accepted
the cosolvent is placed there, otherwise a local search is performed in the neighbors of the point
Expand All @@ -776,9 +777,9 @@ def accept_reject(self,
:param valid_ids: valid halton indices
:type valid_ids: list
:param lowerBound: lower bound of the box
:type lowerBound: openmm.unit.Quantity | Vec3
:type lowerBound: Union[openmm.unit.Quantity, Vec3]
:param upperBound: upper bound of the box
:type upperBound: openmm.unit.Quantity | Vec3
:type upperBound: Union[openmm.unit.Quantity, Vec3]
:param protein_kdtree: tree of the protein's positions
:type protein_kdtree: spatial.cKDTree
:return: accepted coordinates for the cosolvent and the used halton ids
Expand Down Expand Up @@ -812,16 +813,16 @@ def accept_reject(self,

def is_in_box(self,
xyzs: np.ndarray,
lowerBound: openmmunit.Quantity | Vec3,
upperBound: openmmunit.Quantity | Vec3) -> bool:
lowerBound: Union[openmmunit.Quantity, Vec3],
upperBound: Union[openmmunit.Quantity, Vec3]) -> bool:
"""Checks if the coordinates are in the box or not
:param xyzs: coordinates to check
:type xyzs: np.ndarray
:param lowerBound: lower bound of the box
:type lowerBound: openmmunit.Quantity | Vec3
:type lowerBound: Union[openmmunit.Quantity, Vec3]
:param upperBound: upper bound of the box
:type upperBound: openmmunit.Quantity | Vec3
:type upperBound: Union[openmmunit.Quantity, Vec3]
:return: True if all the coordinates are in the box, Flase otherwise
:rtype: bool
"""
Expand Down Expand Up @@ -902,13 +903,13 @@ def calculate_mol_volume(self, mol_positions: np.ndarray) -> float:
points = np.unique(np.hstack(query)).astype(int)
return round(len(points)*mesh_step**3, 2)

def fitting_checks(self) -> float | None:
def fitting_checks(self) -> Union[float, None]:
"""Checks if the required cosolvents can fit in the box and
do not exceed the 50% of the available fillable volume
(volume not occupied by the receptor, if present).
:return: available volume if the cosolvents can fit, None otherwise
:rtype: float | None
:rtype: Union[float, None]
"""
prot_volume = 0
if self.receptor:
Expand All @@ -928,11 +929,11 @@ def fitting_checks(self) -> float | None:
return None
return empty_available_volume

def liters_to_cubic_nanometers(self, liters: float | openmmunit.Quantity) -> float:
def liters_to_cubic_nanometers(self, liters: Union[float, openmmunit.Quantity]) -> float:
"""Converts liters in cubic nanometers
:param liters: volume to convert
:type liters: float | openmm.unit.Quantity
:type liters: Union[float, openmm.unit.Quantity]
:return: converted volume
:rtype: float
"""
Expand Down Expand Up @@ -1006,8 +1007,8 @@ def _build_box(self,
padding: openmmunit.Quantity,
radius: openmmunit.Quantity = None) -> tuple[tuple[Vec3, Vec3, Vec3],
Vec3,
openmmunit.Quantity | Vec3,
openmmunit.Quantity | Vec3]:
Union[openmmunit.Quantity, Vec3],
Union[openmmunit.Quantity, Vec3]]:
"""Builds the simulation box. If a receptor is passed it is used alongside with the padding
parameter to build the box automatically, otherwise a radius has to be passed. If no receptor
the box is centered on the point [0, 0, 0].
Expand All @@ -1021,7 +1022,7 @@ def _build_box(self,
:return: The first element returned is a tuple containing the three vectors describing the simulation box.
The second element is the box itself.
Third and fourth elements are the lower and upper bound of the simulation box.
:rtype: tuple[tuple[Vec3, Vec3, Vec3], Vec3, openmmunit.Quantity | Vec3, openmmunit.Quantity | Vec3]
:rtype: tuple[tuple[Vec3, Vec3, Vec3], Vec3, Union[openmmunit.Quantity, Vec3], Union[openmmunit.Quantity, Vec3]]
"""
padding = padding.value_in_unit(openmmunit.nanometer)
if positions is not None:
Expand Down
Loading

0 comments on commit 2e04017

Please sign in to comment.