Skip to content

Commit

Permalink
fixup! Fix remaining linter complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
padix-key committed Jul 3, 2024
1 parent 95a1c98 commit b190b24
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 111 deletions.
2 changes: 1 addition & 1 deletion doc/bibliography.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ def format_article(self, param):

return Text(*authors, title, journal, volume, pages, date, doi)

except Exception:
except:
warnings.warn(f"Invalid BibTeX entry '{entry.key}'")
return Text(entry.key)
83 changes: 3 additions & 80 deletions doc/examples/scripts/structure/protein/peptide_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,84 +40,7 @@

# Reference peptide bond atom coordinates taken from 1l2y:
# CA, C, N, O, H
peptide_coord = np.array(
[
[-8.608, 3.135, -1.618],
[-7.117, 2.964, -1.897],
[-6.379, 4.031, -2.228],
[-6.634, 1.849, -1.758],
[-6.821, 4.923, -2.394],
]
)


def create_raw_backbone_coord(number_of_res):
"""
Create coordinates for straight peptide chain in z-plane.
The peptide bonds are in trans configuration.
"""
coord = np.zeros((number_of_res * 3, 3))
for i, angle, angle_direction, length in zip(
range(len(coord)),
itertools.cycle([CA_C_N_ANGLE, C_N_CA_ANGLE, N_CA_C_ANGLE]),
itertools.cycle([1, -1]),
itertools.cycle([C_N_LENGTH, N_CA_LENGTH, CA_C_LENGTH]),
):
if i == 0:
coord[i] = [0, 0, 0]
elif i == 1:
coord[i] = [0, length, 0]
else:
# Rotate about z-axis -> backbone lies in z-plane
rot_axis = [0, 0, angle_direction]
# Calculate the coordinates of a new atoms by rotating the previous
# bond by the given angle
new_coord = struc.rotate_about_axis(
coord[i - 2],
axis=rot_axis,
angle=np.deg2rad(angle),
support=coord[i - 1],
)
# Scale bond to correct bond length
bond_vector = new_coord - coord[i - 1]
coord[i] = coord[i - 1] + bond_vector * length / norm(bond_vector)
return coord


def append_residue(chain, residue):
"""
Append a residue to an existing chain.
Modify annotation arrays and remove atoms as necessary.
The atom coordinates are not altered.
"""
if chain.array_length() == 0:
# Chain is empty
residue.res_id[:] = 1
return residue

last_res_id = chain.res_id[-1]

# Remove atoms removed by peptide bond
chain = chain[
(chain.res_id != last_res_id) | ~np.isin(chain.atom_name, ["OXT", "HXT"])
]
residue = residue[~np.isin(residue.atom_name, ["H2", "H3"])]

# Increment residue ID for attached residue
residue.res_id[:] = last_res_id + 1


C_N_LENGTH = 1.34
N_CA_LENGTH = 1.46
CA_C_LENGTH = 1.54

CA_C_N_ANGLE = 114
C_N_CA_ANGLE = 123
N_CA_C_ANGLE = 110

# Reference peptide bond atom coordinates taken from 1l2y:
# CA, C, N, O, H
peptide_coord = np.array(
PEPTIDE_COORD = np.array(
[
[-8.608, 3.135, -1.618],
[-7.117, 2.964, -1.897],
Expand Down Expand Up @@ -221,9 +144,9 @@ def assemble_peptide(sequence):
for atom_name in ["N", "H"]
]
_, transformation = struc.superimpose(
chain.coord[[ca_i, c_i, n_i]], peptide_coord[:3]
chain.coord[[ca_i, c_i, n_i]], PEPTIDE_COORD[:3]
)
chain.coord[[o_i, h_i]] = transformation.apply(peptide_coord[3:])
chain.coord[[o_i, h_i]] = transformation.apply(PEPTIDE_COORD[3:])
return chain


Expand Down
4 changes: 2 additions & 2 deletions doc/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def pymol_scraper(block, block_vars, gallery_conf):
)

try:
import ammolite
import pymol
import ammolite # noqa: F401
import pymol # noqa: F401
except ImportError:
# If Ammolite is not installed, fall back to the image file,
# if already existing
Expand Down
2 changes: 1 addition & 1 deletion doc/switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# information.

__author__ = "Patrick Kunzmann"
__all__ = ["create_api_doc", "skip_non_methods"]
__all__ = ["create_switcher_json"]

import json
import re
Expand Down
2 changes: 1 addition & 1 deletion setup_ccd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import gzip
import logging
from pathlib import Path
from dataclasses import dataclass
from io import StringIO
from pathlib import Path
import numpy as np
import requests
from biotite.structure.io.pdbx import *
Expand Down
2 changes: 1 addition & 1 deletion src/biotite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

from .copyable import *
from .file import *
from .version import __version__, __version_tuple__
from .version import __version__, __version_tuple__ # noqa: F401
from .visualize import *
3 changes: 2 additions & 1 deletion src/biotite/application/muscle/app3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import subprocess
import warnings
from collections.abc import Sequence
from tempfile import NamedTemporaryFile
from biotite.application.application import AppState, VersionError, requires_state
from biotite.application.localapp import cleanup_tempfile
Expand Down Expand Up @@ -136,7 +137,7 @@ def set_gap_penalty(self, gap_penalty):
raise ValueError("Gap penalty must be negative")
self._gap_open = gap_penalty
self._gap_ext = gap_penalty
elif type(gap_penalty) == tuple:
elif isinstance(gap_penalty, Sequence):
if gap_penalty[0] > 0 or gap_penalty[1] > 0:
raise ValueError("Gap penalty must be negative")
self._gap_open = gap_penalty[0]
Expand Down
5 changes: 3 additions & 2 deletions src/biotite/sequence/align/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numbers
import textwrap
from collections.abc import Sequence
import numpy as np
from biotite.sequence.alphabet import LetterAlphabet

Expand Down Expand Up @@ -519,10 +520,10 @@ def score(alignment, matrix, gap_penalty=-10, terminal_penalty=True):
score += matrix[code_i, code_j]

# Sum gap penalties
if type(gap_penalty) == int:
if isinstance(gap_penalty, numbers.Real):
gap_open = gap_penalty
gap_ext = gap_penalty
elif type(gap_penalty) == tuple:
elif isinstance(gap_penalty, Sequence):
gap_open = gap_penalty[0]
gap_ext = gap_penalty[1]
else:
Expand Down
4 changes: 2 additions & 2 deletions src/biotite/sequence/codon.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ def load(table_name):
for line in lines:
if not line:
table_found = False
if type(table_name) == int and line.startswith("id"):
if isinstance(table_name, Integral) and line.startswith("id"):
# remove identifier 'id'
if table_name == int(line[2:]):
table_found = True
elif type(table_name) == str and line.startswith("name"):
elif isinstance(table_name, str) and line.startswith("name"):
# Get list of table names from lines
# (separated with ';')
# remove identifier 'name'
Expand Down
4 changes: 2 additions & 2 deletions src/biotite/sequence/graphics/plasmid.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def __init__(
bbox = Bbox.from_extents(0, 0, 0, 0)
# Draw features as curved arrows (feature indicator)
indicator = axes.add_artist(
Feature_Indicator(
FeatureIndicator(
axes,
self.zorder + 1,
feature,
Expand Down Expand Up @@ -340,7 +340,7 @@ def draw(self, renderer, *args, **kwargs):
)
indicator.set_bbox(bbox)

class Feature_Indicator(Artist):
class FeatureIndicator(Artist):
def __init__(
self,
axes,
Expand Down
2 changes: 1 addition & 1 deletion src/biotite/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@
from .sse import *
from .superimpose import *
from .transform import *
# util and resutil are used internally
# util and segments are used internally
9 changes: 8 additions & 1 deletion src/biotite/structure/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
]

import numpy as np
from biotite.structure.resutil import *
from biotite.structure.segments import (
apply_segment_wise,
get_segment_masks,
get_segment_positions,
get_segment_starts_for,
segment_iter,
spread_segment_wise,
)


def get_chain_starts(array, add_exclusive_stop=False):
Expand Down
4 changes: 2 additions & 2 deletions src/biotite/structure/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def filter_first_altloc(atoms, altloc_ids):
# And filter all atoms for each residue with the first altloc ID
residue_starts = get_residue_starts(atoms, add_exclusive_stop=True)
for start, stop in zip(residue_starts[:-1], residue_starts[1:]):
letter_altloc_ids = [l for l in altloc_ids[start:stop] if l.isalpha()]
letter_altloc_ids = [loc for loc in altloc_ids[start:stop] if loc.isalpha()]
if len(letter_altloc_ids) > 0:
first_id = letter_altloc_ids[0]
altloc_filter[start:stop] |= altloc_ids[start:stop] == first_id
Expand Down Expand Up @@ -572,7 +572,7 @@ def filter_highest_occupancy_altloc(atoms, altloc_ids, occupancies):
occupancies_in_res = occupancies[start:stop]
altloc_ids_in_res = altloc_ids[start:stop]

letter_altloc_ids = [l for l in altloc_ids_in_res if l.isalpha()]
letter_altloc_ids = [loc for loc in altloc_ids_in_res if loc.isalpha()]

if len(letter_altloc_ids) > 0:
highest = -1.0
Expand Down
2 changes: 1 addition & 1 deletion src/biotite/structure/io/pdbx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ def _determine_entity_id(chain_id):
for i in range(len(chain_id)):
try:
entity_id[i] = id_translation[chain_id[i]]
except:
except KeyError:
# chain_id is not in dictionary -> new entry
id_translation[chain_id[i]] = id
entity_id[i] = id_translation[chain_id[i]]
Expand Down
9 changes: 8 additions & 1 deletion src/biotite/structure/residues.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
]

import numpy as np
from biotite.structure.resutil import *
from biotite.structure.segments import (
apply_segment_wise,
get_segment_masks,
get_segment_positions,
get_segment_starts_for,
segment_iter,
spread_segment_wise,
)


def get_residue_starts(array, add_exclusive_stop=False):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/biotite/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, text, width, height, mode):
self._width = width
self._height = height

def draw_path(self, renderer, gc, tpath, affine, rgbFace=None):
def draw_path(self, renderer, gc, tpath, affine, rgbFace=None): # noqa: N803
ax = self._text.axes
try:
renderer = ax.get_figure().canvas.get_renderer()
Expand Down
14 changes: 7 additions & 7 deletions tests/structure/test_basepairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def test_base_pairs_reverse(nuc_sample_array, basepairs, unique_bool):

# Reverse sequence of residues in nuc_sample_array
reversed_nuc_sample_array = struc.AtomArray(0)
for residue in reversed_iterator(struc.residue_iter(nuc_sample_array)):
reversed_nuc_sample_array = reversed_nuc_sample_array + residue
for res in reversed_iterator(struc.residue_iter(nuc_sample_array)):
reversed_nuc_sample_array = reversed_nuc_sample_array + res

computed_basepairs = struc.base_pairs(reversed_nuc_sample_array, unique=unique_bool)
check_residue_starts(computed_basepairs, reversed_nuc_sample_array)
Expand All @@ -117,8 +117,8 @@ def test_base_pairs_reverse_no_hydrogen(nuc_sample_array, basepairs):
nuc_sample_array = nuc_sample_array[nuc_sample_array.element != "H"]
# Reverse sequence of residues in nuc_sample_array
reversed_nuc_sample_array = struc.AtomArray(0)
for residue in reversed_iterator(struc.residue_iter(nuc_sample_array)):
reversed_nuc_sample_array = reversed_nuc_sample_array + residue
for res in reversed_iterator(struc.residue_iter(nuc_sample_array)):
reversed_nuc_sample_array = reversed_nuc_sample_array + res

computed_basepairs = struc.base_pairs(reversed_nuc_sample_array)
check_residue_starts(computed_basepairs, reversed_nuc_sample_array)
Expand Down Expand Up @@ -154,10 +154,10 @@ def test_base_pairs_reordered(nuc_sample_array, seed):
nuc_sample_array_reordered = struc.AtomArray(0)
np.random.seed(seed)

for residue in struc.residue_iter(nuc_sample_array):
bound = residue.array_length()
for res in struc.residue_iter(nuc_sample_array):
bound = res.array_length()
indices = np.random.choice(np.arange(bound), bound, replace=False)
nuc_sample_array_reordered += residue[..., indices]
nuc_sample_array_reordered += res[..., indices]

assert np.all(
struc.base_pairs(nuc_sample_array)
Expand Down
2 changes: 1 addition & 1 deletion tests/structure/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_mass():
assert np.all(np.round(multiple_of_h_masses, decimals=2) % 1 == 0)


def test_protOr_radii():
def test_protor_radii():
"""
Assert that ProtOr VdW radii (except hydrogen) can be calculated for
all atoms in the given structure, since the structure (1GYA)
Expand Down
6 changes: 5 additions & 1 deletion tests/structure/test_mol.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ def test_header_conversion():
),
)
def test_structure_conversion(
FileClass, path, version, omit_charge, use_charge_property
FileClass, # noqa: N803
path,
version,
omit_charge,
use_charge_property,
):
"""
After reading a file, writing the structure back to a new file
Expand Down
6 changes: 4 additions & 2 deletions tests/structure/test_sasa.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def test_single(pdb_id):
sasa = struc.sasa(array, vdw_radii="Single", point_number=5000)

import mdtraj
from biotite.structure.info.radii import _SINGLE_RADII as radii
from biotite.structure.info.radii import _SINGLE_RADII as SINGLE_RADII

# Use the same atom radii
radii = {element.capitalize(): radius / 10 for element, radius in radii.items()}
radii = {
element.capitalize(): radius / 10 for element, radius in SINGLE_RADII.items()
}
traj = mdtraj.load(file_name)
# Conversion from nm^2 to A^2
sasa_exp = (
Expand Down

0 comments on commit b190b24

Please sign in to comment.