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

refactor: fix wrong type Residue -> DefinitionResidue #412

Merged
merged 9 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 55 additions & 49 deletions pdb2pqr/aa.py

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions pdb2pqr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
.. codeauthor:: Nathan Baker (et al.)
"""

from __future__ import annotations

import argparse
import logging
import sys
Expand Down
26 changes: 16 additions & 10 deletions pdb2pqr/na.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@

from . import residue
from . import structures as struct
from .definitions import DefinitionResidue
from .pdb import ATOM, HETATM


class Nucleic(residue.Residue):
"""This class provides standard features of the nucleic acids listed below."""

def __init__(self, atoms, ref):
def __init__(self, atoms: list[ATOM | HETATM], ref: DefinitionResidue):
sample_atom = atoms[-1]

self.atoms = []
self.atoms: list[struct.Atom] = []
self.name = sample_atom.res_name
self.chain_id = sample_atom.chain_id
self.res_seq = sample_atom.res_seq
self.ins_code = sample_atom.ins_code

self.ffname = self.name
self.map = {}
self.map: dict[str, struct.Atom] = {}
self.dihedrals = []
self.patches = []
self.is3term = 0
Expand All @@ -42,7 +44,11 @@ def __init__(self, atoms, ref):
atom_ = struct.Atom(atom, "ATOM", self)
self.add_atom(atom_)

def create_atom(self, atomname, newcoords):
def create_atom(
self,
atomname: str,
newcoords: list[float] | tuple[float, float, float],
):
"""Create an atom.

Overrides the generic residue's create_atom().
Expand All @@ -66,7 +72,7 @@ def create_atom(self, atomname, newcoords):
newatom.added = 1
self.add_atom(newatom)

def add_atom(self, atom):
def add_atom(self, atom: struct.Atom):
"""Add existing atom to system.

Override the existing add_atom - include the link to the reference
Expand Down Expand Up @@ -109,7 +115,7 @@ def set_state(self):
class ADE(Nucleic):
"""Adenosine class."""

def __init__(self, atoms, ref):
def __init__(self, atoms, ref: DefinitionResidue):
"""Initialize residue.

:param atoms: add atoms to residue
Expand Down Expand Up @@ -140,7 +146,7 @@ def set_state(self):
class CYT(Nucleic):
"""Cytidine class"""

def __init__(self, atoms, ref):
def __init__(self, atoms, ref: DefinitionResidue):
"""Initialize residue.

:param atoms: add atoms to residue
Expand Down Expand Up @@ -171,7 +177,7 @@ def set_state(self):
class GUA(Nucleic):
"""Guanosine class"""

def __init__(self, atoms, ref):
def __init__(self, atoms, ref: DefinitionResidue):
"""Initialize residue.

:param atoms: add atoms to residue
Expand Down Expand Up @@ -202,7 +208,7 @@ def set_state(self):
class THY(Nucleic):
"""Thymine class"""

def __init__(self, atoms, ref):
def __init__(self, atoms, ref: DefinitionResidue):
"""Initialize residue.

:param atoms: add atoms to residue
Expand Down Expand Up @@ -231,7 +237,7 @@ def set_state(self):
class URA(Nucleic):
"""Uridine class"""

def __init__(self, atoms, ref):
def __init__(self, atoms, ref: DefinitionResidue):
"""Initialize residue.

:param atoms: add atoms to residue
Expand Down
2 changes: 0 additions & 2 deletions pdb2pqr/residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
.. codeauthor:: Nathan Baker
"""

from __future__ import annotations

import logging

from . import pdb, structures
Expand Down
19 changes: 13 additions & 6 deletions pdb2pqr/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
.. codeauthor:: Nathan Baker
"""

# from . import pdb
from typing import Self

from .config import BACKBONE
from .pdb import ATOM, HETATM


class Chain:
Expand All @@ -19,7 +20,7 @@ class Chain:
:class:`Biomolecule` object.
"""

def __init__(self, chain_id):
def __init__(self, chain_id: str):
"""Initialize the class.

:param chain_id: ID for this chain as denoted in the PDB
Expand Down Expand Up @@ -74,7 +75,12 @@ class Atom:
:class:`HETATM` objects into a single class.
"""

def __init__(self, atom=None, type_="ATOM", residue=None):
def __init__(
self,
atom: ATOM | HETATM | Self | None = None,
type_="ATOM",
residue=None,
):
"""Initialize the new Atom object by using the old object.

:param atom: the original ATOM object (could be None)
Expand Down Expand Up @@ -136,10 +142,11 @@ def __init__(self, atom=None, type_="ATOM", residue=None):
self.element = atom.element
self.charge = atom.charge
self.residue = residue
try:
self.mol2charge = atom.mol2charge
except AttributeError:
if isinstance(atom, ATOM):
sobolevnrm marked this conversation as resolved.
Show resolved Hide resolved
# ATOM class doesn't have mol2charge
self.mol2charge = None
else:
self.mol2charge = atom.mol2charge

@classmethod
def from_pqr_line(cls, line):
Expand Down
90 changes: 89 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "code"
path = "pdb2pqr/_version.py"
# expression = "__version__" # default

[tool.hatch.build.targets.sdist]
include = [
"pdb2pqr",
"docs",
"examples",
"tests",
]

[tool.hatch.build.targets.wheel]
packages = ["pdb2pqr"]

[project]
name = "pdb2pqr"
dynamic = ["version"]
description = """
Automates many of the common tasks of preparing structures for \
continuum solvation calculations as well as many other types of \
biomolecular structure modeling, analysis, and simulation."""
authors = [
{ name = "Jens Erik Nielsen" },
{ name = "Nathan Baker", email = "[email protected]" },
]
readme = "README.md"
license = { file = "LICENSE.md" }
# NOTE: make sure you change [tool.pyright] pythonVersion to match this
requires-python = ">=3.11,<4"
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Scientific/Engineering :: Chemistry",
]
keywords = ["science", "chemistry", "molecular biology"]

dependencies = [
"mmcif_pdbx>=1.1.2",
"numpy",
"propka >= 3.5",
"requests",
"docutils < 0.18",
]

[project.optional-dependencies]
dev = ["check-manifest"]
test = [
"ruff",
"coverage",
"pandas >= 1.0",
"pytest",
"testfixtures",
]

[project.urls]
"Homepage" = "https://www.poissonboltzmann.org"
"Documentation"= "https://pdb2pqr.readthedocs.io/"
"Get help"= "https://github.com/Electrostatics/pdb2pqr/issues"
"Publications"= "https://pubmed.ncbi.nlm.nih.gov/?term=R01+GM069702"
"Funding"= "https://bit.ly/apbs-funding"
"Source"= "https://github.com/Electrostatics/pdb2pqr"

[project.scripts]
pdb2pqr = "pdb2pqr.main:main"
pdb2pqr30 = "pdb2pqr.main:main"
dx2cube = "pdb2pqr.main:dx_to_cube"
inputgen = "pdb2pqr.inputgen:main"


[tool.pytest.ini_options]
testpaths = ["tests"]
log_cli = true
Expand All @@ -19,7 +106,7 @@ typeCheckingMode = "standard"
useLibraryCodeForTypes = true
autoImportCompletions = true

pythonVersion = "3.8"
pythonVersion = "3.11"
# pythonPlatform = "Linux"

reportDuplicateImport = true
Expand Down Expand Up @@ -94,6 +181,7 @@ ignore = [
"UP017", # datetime.timezone.utc -> datetime.UTC
"SIM108", # use ternary operator instead of if-else
"TRY003", # long message in except
"PLR2004", # magic value comparison
]

[tool.ruff.lint.per-file-ignores]
Expand Down
1 change: 0 additions & 1 deletion ruff_essential.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ select = [
"F63",
"F7",
"F82",
"FA102", # Python 3.10-style union typing is used so we need to import `from __future__ import annotations`
]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

115 changes: 0 additions & 115 deletions setup.py

This file was deleted.

Loading