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

perf: features.contact #220

Merged
merged 38 commits into from Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ffcd1f2
numpy -> np
DaniBodor Nov 1, 2022
9d48d0c
distance, covalent, samechain
DaniBodor Nov 1, 2022
209e8c5
electrostatic
DaniBodor Nov 1, 2022
4a3fda8
temporary testing notebook
DaniBodor Nov 1, 2022
2ea2ae9
update to notebook
DaniBodor Nov 1, 2022
c2c084c
epsilon fix
DaniBodor Nov 1, 2022
5b68522
vdw potentials
DaniBodor Nov 1, 2022
df66ac8
added option to raise/override UnknownAtomError inside the forcefield…
DaniBodor Nov 1, 2022
5f1f636
removed obsolete code from add residue features
DaniBodor Nov 1, 2022
6f1f040
simplified functions for get potentials
DaniBodor Nov 1, 2022
6a0766f
check for inter vs intra parameters
DaniBodor Nov 1, 2022
93d832e
minor changes to get_potentials functions
DaniBodor Nov 1, 2022
be7ce66
aligned pdb.py (i think obsolete to be deleted)
DaniBodor Nov 1, 2022
adb8605
untracking notebook
DaniBodor Nov 1, 2022
66c6218
simplified atomic contacts calculations
DaniBodor Nov 1, 2022
b51c0ff
deleted obsolete code and renamed functions
DaniBodor Nov 1, 2022
67e2a59
docstrings and linting
DaniBodor Nov 1, 2022
9aace17
commented on some unused functions
DaniBodor Nov 1, 2022
61ee8ba
deleted obsolete functions
DaniBodor Nov 1, 2022
4688b0f
convert naming to internal functions
DaniBodor Nov 1, 2022
d3b4021
removed optional UnknownAtomError in forcefield
DaniBodor Nov 1, 2022
24c9f9f
unused imports
DaniBodor Nov 1, 2022
0005a27
assign SAMERES feature in atomic models
DaniBodor Nov 1, 2022
c4f77a7
prospector
DaniBodor Nov 1, 2022
53d6370
prospector
DaniBodor Nov 1, 2022
2bc1eb2
Merge pull request #221 from DeepRank/obsolete_pdb_code
DaniBodor Nov 1, 2022
54ba328
removed more unused functions
DaniBodor Nov 1, 2022
b81b385
passing distances instead of recalculating
DaniBodor Nov 2, 2022
5cf9606
prettier np function
DaniBodor Nov 2, 2022
c98c8d7
updated LJ potentials functions
DaniBodor Nov 7, 2022
b921bfd
add_features with one-shot calculations
DaniBodor Nov 7, 2022
8bdd933
updated coulomb function
DaniBodor Nov 7, 2022
fb51b7b
updated doc strings
DaniBodor Nov 7, 2022
c7c5a67
fixed minor bug
DaniBodor Nov 7, 2022
945cd47
linting
DaniBodor Nov 7, 2022
1df1922
Merge pull request #226 from DeepRank/atomiccontact_speed
DaniBodor Nov 8, 2022
bf3a136
Merge branch 'main' into add_features_for_residues
DaniBodor Nov 8, 2022
63e1af1
Merge branch 'add_features_for_residues' of github.com:DeepRank/deepr…
DaniBodor Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 16 additions & 19 deletions deeprankcore/domain/forcefield/__init__.py
Expand Up @@ -7,9 +7,10 @@
from deeprankcore.tools.forcefield.patch import PatchParser
from deeprankcore.tools.forcefield.residue import ResidueClassParser
from deeprankcore.tools.forcefield.param import ParamParser
from deeprankcore.models.error import UnknownAtomError
from deeprankcore.models.forcefield.vanderwaals import VanderwaalsParam

logging.getLogger(__name__)

_log = logging.getLogger(__name__)


_forcefield_directory_path = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -58,17 +59,12 @@ def _find_matching_residue_class(self, residue: Residue):
return None

def get_vanderwaals_parameters(self, atom: Atom):
type_ = self._get_type(atom)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need type_ var?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used for getting the right vanderwaals parameters from the table file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I could see it was only used internally by the get_vanderwaals_parameters function. However, this function basically did nothing else than read the type_ and get the parameters, so instead I merged get_type into get_vanderwaals_parameters.
I tested that old and new add_features functions (from atomic_contact, which uses this) give the exact same result on ~5 test cases, so am fairly confident that it is still being read correctly.


return self._vanderwaals_parameters[type_]

def _get_type(self, atom: Atom):
atom_name = atom.name

if atom.residue.amino_acid is None:
raise UnknownAtomError(f"no amino acid for {atom}")

residue_name = atom.residue.amino_acid.three_letter_code
gcroci2 marked this conversation as resolved.
Show resolved Hide resolved
_log.warning(f"no amino acid for {atom}; three letter code set to XXX")
residue_name = 'XXX'
else: residue_name = atom.residue.amino_acid.three_letter_code

DaniBodor marked this conversation as resolved.
Show resolved Hide resolved
type_ = None

Expand All @@ -86,11 +82,12 @@ def _get_type(self, atom: Atom):

type_ = action["TYPE"]

if type_ is None:
raise UnknownAtomError(
f"not mentioned in top or patch: {top_key}")
if type_ is None: # pylint: disable=no-else-return
_log.warning(f"Atom {atom} is unknown to the forcefield; vanderwaals_parameters set to (0.0, 0.0, 0.0, 0.0)")
return VanderwaalsParam(0.0, 0.0, 0.0, 0.0)
else:
return self._vanderwaals_parameters[type_]

return type_

def get_charge(self, atom: Atom):
"""
Expand Down Expand Up @@ -119,11 +116,11 @@ def get_charge(self, atom: Atom):

charge = float(action["CHARGE"])

if charge is None:
raise UnknownAtomError(
f"not mentioned in top or patch: {top_key}")

return charge
if charge is None: # pylint: disable=no-else-return
_log.warning(f"Atom {atom} is unknown to the forcefield; charge is set to 0.0")
return 0.0
else:
return charge


atomic_forcefield = AtomicForcefield()
11 changes: 1 addition & 10 deletions deeprankcore/feature/atom.py
Expand Up @@ -2,7 +2,6 @@
from deeprankcore.models.graph import Graph
from deeprankcore.domain.forcefield import atomic_forcefield
from deeprankcore.domain.features import nodefeats
from deeprankcore.models.error import UnknownAtomError
import logging


Expand All @@ -21,12 +20,4 @@ def add_features( # pylint: disable=unused-argument

node.features[nodefeats.ATOMTYPE] = atom.element.onehot
node.features[nodefeats.PDBOCCUPANCY] = atom.occupancy

try:
node.features[nodefeats.ATOMCHARGE] = atomic_forcefield.get_charge(atom)

except UnknownAtomError:
_log.warning(f"Ignoring atom {atom}, because it's unknown to the forcefield")

# set parameters to zero, so that the potential becomes zero
node.features[nodefeats.ATOMCHARGE] = 0.0
node.features[nodefeats.ATOMCHARGE] = atomic_forcefield.get_charge(atom)