Skip to content
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.22
rev: v0.16.6
hooks:
# Run the linter.
- id: ruff
Expand All @@ -25,7 +25,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: 9.0.0b1
rev: 9.0.1
hooks:
- id: isort
name: isort (python)
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# mbuild documentation build configuration file, created by
# sphinx-quickstart on Wed Oct 1 08:59:12 2014.
Expand All @@ -14,8 +13,8 @@

import os
import sys
from unittest import mock

import mock
import sphinx_rtd_theme

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
13 changes: 6 additions & 7 deletions docs/sphinxext/notebook_sphinxext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copied from the mdtraj project, commit 3fddb5d (Mar 10, 2016)

from __future__ import print_function

import os
import shutil
Expand All @@ -12,7 +11,7 @@


def _read(wd, name):
with open("{}/{}.ipynb".format(wd, name)) as f:
with open(f"{wd}/{name}.ipynb") as f:
notebook = nbformat.read(f, as_version=4)
return notebook

Expand All @@ -37,7 +36,7 @@ def export_html(wd, name):
body, resources = exporter.from_notebook_node(nb)

for fn, data in resources["outputs"].items():
with open("{}/{}".format(wd, fn), "wb") as f:
with open(f"{wd}/{fn}", "wb") as f:
f.write(data)
return body
except Exception as e:
Expand All @@ -48,7 +47,7 @@ def export_python(wd, name):
nb = _read(wd, name)
exporter = PythonExporter()
body, resources = exporter.from_notebook_node(nb)
with open("{}/{}.py".format(wd, name), "w") as f:
with open(f"{wd}/{name}.py", "w") as f:
f.write(body)


Expand All @@ -67,11 +66,11 @@ def run(self):

# get path to notebook
nb_rel_path = self.arguments[0]
nb_abs_path = "{}/../{}".format(setup.confdir, nb_rel_path)
nb_abs_path = f"{setup.confdir}/../{nb_rel_path}"
nb_abs_path = os.path.abspath(nb_abs_path)
nb_name = os.path.basename(nb_rel_path).split(".")[0]
dest_dir = "{}/{}/{}".format(
setup.app.builder.outdir, os.path.dirname(nb_rel_path), nb_name
dest_dir = (
f"{setup.app.builder.outdir}/{os.path.dirname(nb_rel_path)}/{nb_name}"
)
fmt = {"wd": dest_dir, "name": nb_name}

Expand Down
1 change: 0 additions & 1 deletion mbuild/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# ruff: noqa: F401
# ruff: noqa: F403
"""mBuild: a hierarchical, component based molecule builder."""

import logging
Expand Down
2 changes: 1 addition & 1 deletion mbuild/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger = logging.getLogger(__name__)


class Box(object):
class Box:
"""A box representing the bounds of the system.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion mbuild/coarse_graining.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, compound):
name = "G"
else:
name = compound.name + "_PROXY"
super(Proxy, self).__init__(name=name)
super().__init__(name=name)

self.wrapped = compound
self.children = None
Expand Down
19 changes: 6 additions & 13 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import os
import tempfile
from collections import OrderedDict
from collections.abc import Iterable
from collections.abc import Iterable, Sequence
from copy import deepcopy
from typing import Sequence

import ele
import networkx as nx
Expand All @@ -26,7 +25,7 @@
from mbuild.utils.io import import_, run_from_ipython
from mbuild.utils.jsutils import overwrite_nglview_default

__all__ = ["clone", "Compound", "Particle"]
__all__ = ["Compound", "Particle", "clone"]

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,7 +61,7 @@ def clone(existing_compound, clone_of=None, root_container=None):
return newone


class Compound(object):
class Compound:
"""A building block in the mBuild hierarchy.

Compound is the superclass of all composite building blocks in the mBuild
Expand Down Expand Up @@ -157,7 +156,7 @@ def __init__(
element=None,
port_particle=False,
):
super(Compound, self).__init__()
super().__init__()

if name:
if not isinstance(name, str):
Expand Down Expand Up @@ -358,13 +357,7 @@ def print_hierarchy(self, print_full=False, index=None, show_tree=True):
if h["level"] == 0:
count = count + 1
if print_full:
if index is None:
tree.create_node(
f"[{h['comp'].name}]: {h['comp'].n_particles} particles, {n_bonds} bonds, {len(h['comp'].children)} children",
f"{h['comp_id']}",
f"{h['parent_id']}",
)
elif count == index:
if index is None or count == index:
tree.create_node(
f"[{h['comp'].name}]: {h['comp'].n_particles} particles, {n_bonds} bonds, {len(h['comp'].children)} children",
f"{h['comp_id']}",
Expand Down Expand Up @@ -1318,7 +1311,7 @@ def box(self, box):
raise ValueError("Ports cannot have a box")
# Make sure the box is bigger than the bounding box
if box is not None:
if np.asarray((box.lengths < self.get_boundingbox().lengths)).any():
if np.asarray(box.lengths < self.get_boundingbox().lengths).any():
logger.warning(
"Compound.box.lengths < Compound.boundingbox.lengths. "
"There may be particles outside of the defined "
Expand Down
8 changes: 4 additions & 4 deletions mbuild/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def load_pybel_smiles(
mymol = pybel.readstring("smi", smiles_or_filename)
mymolGen = [mymol]
# Now we treat it as a filename
except (OSError, IOError):
except OSError:
mymolGen = pybel.readfile("smi", smiles_or_filename)

for mymol in mymolGen:
Expand Down Expand Up @@ -996,7 +996,7 @@ def save(
formats.json_formats.compound_to_json : Write to a json file
"""
if os.path.exists(filename) and not overwrite:
raise IOError(f"{filename} exists; not overwriting")
raise OSError(f"{filename} exists; not overwriting")
if compound.charge:
if round(compound.charge, 4) != 0.0:
logger.info(
Expand Down Expand Up @@ -1588,7 +1588,7 @@ def _to_topology(compound, atom_list, chains=None, residues=None):
# Ensure that both atoms are part of the compound. This becomes an
# issue if you try to convert a sub-compound to a topology which is
# bonded to a different subcompound.
if all(a in atom_mapping.keys() for a in [atom1, atom2]):
if all(a in atom_mapping for a in [atom1, atom2]):
top.add_bond(atom_mapping[atom1], atom_mapping[atom2])
return top

Expand Down Expand Up @@ -1848,7 +1848,7 @@ def _iterate_children(compound, nodes, edges, names_only=False):
for child in compound.children:
if names_only:
unique_name = child.name + "_" + str(id(child))
unique_name_parent = child.parent.name + "_" + str((id(child.parent)))
unique_name_parent = child.parent.name + "_" + str(id(child.parent))
nodes.append(unique_name)
edges.append([unique_name_parent, unique_name])
else:
Expand Down
20 changes: 10 additions & 10 deletions mbuild/coordinate_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def force_overlap(
)


class CoordinateTransform(object):
class CoordinateTransform:
"""Coordinate transforms."""

def __init__(self, T=None):
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, P):
T[0, 3] = P[0]
T[1, 3] = P[1]
T[2, 3] = P[2]
super(Translation, self).__init__(T)
super().__init__(T)


class RotationAroundZ(CoordinateTransform):
Expand All @@ -117,7 +117,7 @@ def __init__(self, theta):
T[0, 1] = -np.sin(theta)
T[1, 0] = np.sin(theta)
T[1, 1] = np.cos(theta)
super(RotationAroundZ, self).__init__(T)
super().__init__(T)


class RotationAroundY(CoordinateTransform):
Expand All @@ -129,7 +129,7 @@ def __init__(self, theta):
T[0, 2] = np.sin(theta)
T[2, 0] = -np.sin(theta)
T[2, 2] = np.cos(theta)
super(RotationAroundY, self).__init__(T)
super().__init__(T)


class RotationAroundX(CoordinateTransform):
Expand All @@ -141,7 +141,7 @@ def __init__(self, theta):
T[1, 2] = -np.sin(theta)
T[2, 1] = np.sin(theta)
T[2, 2] = np.cos(theta)
super(RotationAroundX, self).__init__(T)
super().__init__(T)


class Rotation(CoordinateTransform):
Expand Down Expand Up @@ -169,7 +169,7 @@ def __init__(self, theta, around):
]
)
T[0:3, 0:3] = m
super(Rotation, self).__init__(T)
super().__init__(T)


class ChangeOfBasis(CoordinateTransform):
Expand All @@ -186,7 +186,7 @@ def __init__(self, basis, origin=None):
T = inv(T)

T[0:3, 3:4] = -np.array([origin]).transpose()
super(ChangeOfBasis, self).__init__(T)
super().__init__(T)


class AxisTransform(CoordinateTransform):
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(self, new_origin=None, point_on_x_axis=None, point_on_xy_plane=None
# The concatentaion of translation and rotation.
B_tr = np.dot(B, T_tr)

super(AxisTransform, self).__init__(B_tr)
super().__init__(B_tr)


class RigidTransform(CoordinateTransform):
Expand All @@ -250,7 +250,7 @@ def __init__(self, A, B):
H = np.zeros((3, 3), dtype=float)

for i in range(rows):
H = H + np.transpose(A[i, :] - centroid_A).dot((B[i, :] - centroid_B))
H = H + np.transpose(A[i, :] - centroid_A).dot(B[i, :] - centroid_B)

U, _, V = svd(H)
V = np.transpose(V)
Expand All @@ -275,7 +275,7 @@ def __init__(self, A, B):

T = C_B.dot(R_new).dot(C_A)

super(RigidTransform, self).__init__(T)
super().__init__(T)


def unit_vector(v):
Expand Down
Loading
Loading