Skip to content

Commit

Permalink
Reformat code using the new black
Browse files Browse the repository at this point in the history
  • Loading branch information
MBartkowiakSTFC committed Jan 26, 2024
1 parent 9ead5a1 commit 897b369
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 185 deletions.
8 changes: 5 additions & 3 deletions MDANSE/Src/MDANSE/Framework/Configurators/IConfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ def __init__(self, name, **kwargs):

self._label = kwargs.get(
"label",
self.__class__._label
if hasattr(self.__class__, "_label")
else " ".join(name.split("_")).strip(),
(
self.__class__._label
if hasattr(self.__class__, "_label")
else " ".join(name.split("_")).strip()
),
)

self._widget = kwargs.get("widget", self.__class__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def _generate(self):
)

hklMax = (
np.ceil([qMax / np.sqrt(np.sum(v**2)) for v in self._inverseUnitCell.T])
+ 1
np.ceil([qMax / np.sqrt(np.sum(v**2)) for v in self._inverseUnitCell.T]) + 1
)

vects = np.mgrid[
Expand Down
2 changes: 0 additions & 2 deletions MDANSE/Src/MDANSE/IO/FortranFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
# which can be accessed as text or as a list of items.
#
class FortranLine:

"""Fortran-style record in formatted files
FortranLine objects represent the content of one record of a
Expand Down Expand Up @@ -244,7 +243,6 @@ def _output(self):
# little error checking.
#
class FortranFormat:

"""
Parsed Fortran-style format string
Expand Down
12 changes: 0 additions & 12 deletions MDANSE/Src/MDANSE/IO/PDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def cmp(a, b):
# for everything.
#
class PDBFile:

"""
X{PDB} file with access at the record level
Expand Down Expand Up @@ -551,7 +550,6 @@ def __del__(self):
# Representation of objects.
#
class PDBAtom:

"""
Atom in a PDB structure
"""
Expand Down Expand Up @@ -638,7 +636,6 @@ def writeToFile(self, file):


class PDBHetAtom(PDBAtom):

"""
HetAtom in a PDB structure
Expand All @@ -651,7 +648,6 @@ def type(self):


class PDBGroup:

"""
Atom group (residue or molecule) in a PDB file
Expand Down Expand Up @@ -771,7 +767,6 @@ def writeToFile(self, file):


class PDBMolecule(PDBGroup):

"""
Molecule in a PDB file
Expand All @@ -789,7 +784,6 @@ class PDBResidue(PDBGroup):


class PDBAminoAcidResidue(PDBResidue):

"""
Amino acid residue in a PDB file
"""
Expand Down Expand Up @@ -850,7 +844,6 @@ def writeToFile(self, file):


class PDBNucleotideResidue(PDBResidue):

"""
Nucleotide residue in a PDB file
"""
Expand Down Expand Up @@ -922,7 +915,6 @@ def writeToFile(self, file):


class PDBChain:

"""Chain of PDB residues
This is an abstract base class. Instances can be created using
Expand Down Expand Up @@ -1035,7 +1027,6 @@ def writeToFile(self, file):


class PDBPeptideChain(PDBChain):

"""
Peptide chain in a PDB file
"""
Expand All @@ -1056,7 +1047,6 @@ def isCompatible(self, chain_data, residue_data):


class PDBNucleotideChain(PDBChain):

"""
Nucleotide chain in a PDB file
"""
Expand Down Expand Up @@ -1105,7 +1095,6 @@ def isCompatible(self, chain_data, residue_data):
# Residue number class for dealing with insertion codes
#
class ResidueNumber:

"""
PDB residue number
Expand Down Expand Up @@ -1145,7 +1134,6 @@ def __str__(self):
# The configuration class.
#
class Structure:

"""
A high-level representation of the contents of a PDB file
Expand Down
1 change: 0 additions & 1 deletion MDANSE/Src/MDANSE/IO/TextFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


class TextFile:

"""
Text files with line iteration and transparent compression
Expand Down
3 changes: 0 additions & 3 deletions MDANSE/Src/MDANSE/Mathematics/LinearAlgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def cmp(a, b):


class Vector:

"""Vector in 3D space
Constructor:
Expand Down Expand Up @@ -228,7 +227,6 @@ def angle(self, other):


class Quaternion:

"""
Quaternion (hypercomplex number)
Expand Down Expand Up @@ -387,7 +385,6 @@ def asRotation(self):


class Tensor:

"""Tensor in 3D space
Tensors support the usual arithmetic operations
Expand Down
7 changes: 0 additions & 7 deletions MDANSE/Src/MDANSE/Mathematics/Transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
# Abstract base classes
#
class Transformation:

"""
Linear coordinate transformation.
Expand Down Expand Up @@ -70,7 +69,6 @@ def inverse(self):
# Rigid body transformations
#
class RigidBodyTransformation(Transformation):

"""
Combination of translations and rotations
"""
Expand Down Expand Up @@ -110,7 +108,6 @@ def screwMotion(self):
# Pure translation
#
class Translation(RigidBodyTransformation):

"""
Translational transformation
"""
Expand Down Expand Up @@ -167,7 +164,6 @@ def screwMotion(self):
# Pure rotation
#
class Rotation(RigidBodyTransformation):

"""
Rotational transformation
"""
Expand Down Expand Up @@ -383,7 +379,6 @@ def screwMotion(self):
# Combined translation and rotation
#
class RotationTranslation(RigidBodyTransformation):

"""
Combined translational and rotational transformation.
Expand Down Expand Up @@ -448,7 +443,6 @@ def screwMotion(self):
# Scaling
#
class Scaling(Transformation):

"""
Scaling
"""
Expand Down Expand Up @@ -524,7 +518,6 @@ def inverse(self):
# General linear transformation
#
class LinearTransformation(Transformation):

"""
General linear transformation.
Expand Down
83 changes: 50 additions & 33 deletions MDANSE/Tests/UnitTests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ def test_add_atom_existing_atom(self):
ATOMS_DATABASE.add_atom("H")

def test_add_atom_valid(self):
with patch("json.dump") as m, patch(
"MDANSE.Chemistry.Databases.AtomsDatabase.save"
) as n:
with (
patch("json.dump") as m,
patch("MDANSE.Chemistry.Databases.AtomsDatabase.save") as n,
):
ATOMS_DATABASE.add_atom("new_atom")
self.assertDictEqual({}, ATOMS_DATABASE["new_atom"])
assert not m.called
Expand Down Expand Up @@ -334,9 +335,10 @@ def test__reset(self):
self.assertDictEqual({}, ATOMS_DATABASE._properties)

def test_save(self):
with patch("builtins.open", new_callable=mock_open) as op, patch(
"json.dump"
) as dump:
with (
patch("builtins.open", new_callable=mock_open) as op,
patch("json.dump") as dump,
):
ATOMS_DATABASE.save()
op.assert_called_with(ATOMS_DATABASE._USER_DATABASE, "w")
dump.assert_called_with(
Expand Down Expand Up @@ -383,9 +385,12 @@ def test__load_default_database(self):
self.assertDictEqual(self.data, MOLECULES_DATABASE._data)

def test__load_user_database(self):
with patch(
"builtins.open", new_callable=mock_open, read_data=json.dumps(self.data)
) as m, patch("os.path.exists", spec=True):
with (
patch(
"builtins.open", new_callable=mock_open, read_data=json.dumps(self.data)
) as m,
patch("os.path.exists", spec=True),
):
MOLECULES_DATABASE._load("user.json", "default.json")
m.assert_called_with("user.json", "r")
self.assertDictEqual(self.data, MOLECULES_DATABASE._data)
Expand All @@ -410,9 +415,10 @@ def test_add_molecule_existing_molecule(self):
MOLECULES_DATABASE.add_molecule("WAT")

def test_add_molecule_valid(self):
with patch("json.dump") as m, patch(
"MDANSE.Chemistry.Databases.MoleculesDatabase.save"
) as n:
with (
patch("json.dump") as m,
patch("MDANSE.Chemistry.Databases.MoleculesDatabase.save") as n,
):
MOLECULES_DATABASE.add_molecule("new_molecule")
self.assertDictEqual(
{"alternatives": [], "atoms": {}}, MOLECULES_DATABASE["new_molecule"]
Expand All @@ -438,9 +444,10 @@ def test__reset(self):
self.assertDictEqual({}, MOLECULES_DATABASE._data)

def test_save(self):
with patch("builtins.open", new_callable=mock_open) as op, patch(
"json.dump"
) as dump:
with (
patch("builtins.open", new_callable=mock_open) as op,
patch("json.dump") as dump,
):
MOLECULES_DATABASE.save()
op.assert_called_with(MOLECULES_DATABASE._USER_DATABASE, "w")
dump.assert_called_with(self.data, ANY)
Expand Down Expand Up @@ -489,9 +496,12 @@ def test__load_default_database(self):
)

def test__load_user_database(self):
with patch(
"builtins.open", new_callable=mock_open, read_data=json.dumps(self.data)
) as m, patch("os.path.exists", spec=True):
with (
patch(
"builtins.open", new_callable=mock_open, read_data=json.dumps(self.data)
) as m,
patch("os.path.exists", spec=True),
):
NUCLEOTIDES_DATABASE._load("user.json", "default.json")
m.assert_called_with("user.json", "r")
self.assertDictEqual(self.data, NUCLEOTIDES_DATABASE._data)
Expand Down Expand Up @@ -521,9 +531,10 @@ def test_add_nucleotide_existing_nucleotide(self):
NUCLEOTIDES_DATABASE.add_nucleotide("5T")

def test_add_nucleotide_valid(self):
with patch("json.dump") as m, patch(
"MDANSE.Chemistry.Databases.NucleotidesDatabase.save"
) as n:
with (
patch("json.dump") as m,
patch("MDANSE.Chemistry.Databases.NucleotidesDatabase.save") as n,
):
NUCLEOTIDES_DATABASE.add_nucleotide("new_nucleotide", True, True)
self.assertDictEqual(
{
Expand Down Expand Up @@ -555,9 +566,10 @@ def test__reset(self):
self.assertDictEqual({}, NUCLEOTIDES_DATABASE._data)

def test_save(self):
with patch("builtins.open", new_callable=mock_open) as op, patch(
"json.dump"
) as dump:
with (
patch("builtins.open", new_callable=mock_open) as op,
patch("json.dump") as dump,
):
NUCLEOTIDES_DATABASE.save()
op.assert_called_with(NUCLEOTIDES_DATABASE._USER_DATABASE, "w")
dump.assert_called_with(self.data, ANY)
Expand Down Expand Up @@ -612,9 +624,12 @@ def test__load_default_database(self):
)

def test__load_user_database(self):
with patch(
"builtins.open", new_callable=mock_open, read_data=json.dumps(self.data)
) as m, patch("os.path.exists", spec=True):
with (
patch(
"builtins.open", new_callable=mock_open, read_data=json.dumps(self.data)
) as m,
patch("os.path.exists", spec=True),
):
RESIDUES_DATABASE._load("user.json", "default.json")
m.assert_called_with("user.json", "r")
self.assertDictEqual(self.data, RESIDUES_DATABASE._data)
Expand Down Expand Up @@ -644,9 +659,10 @@ def test_add_residue_existing_nucleotide(self):
RESIDUES_DATABASE.add_residue("G")

def test_add_residue_valid(self):
with patch("json.dump") as m, patch(
"MDANSE.Chemistry.Databases.ResiduesDatabase.save"
) as n:
with (
patch("json.dump") as m,
patch("MDANSE.Chemistry.Databases.ResiduesDatabase.save") as n,
):
RESIDUES_DATABASE.add_residue("new_residues", True, True)
self.assertDictEqual(
{
Expand Down Expand Up @@ -678,9 +694,10 @@ def test__reset(self):
self.assertDictEqual({}, RESIDUES_DATABASE._data)

def test_save(self):
with patch("builtins.open", new_callable=mock_open) as op, patch(
"json.dump"
) as dump:
with (
patch("builtins.open", new_callable=mock_open) as op,
patch("json.dump") as dump,
):
RESIDUES_DATABASE.save()
op.assert_called_with(RESIDUES_DATABASE._USER_DATABASE, "w")
dump.assert_called_with(self.data, ANY)
7 changes: 3 additions & 4 deletions MDANSE_GUI/Src/MDANSE_GUI/GUI/JobControllerPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ def update(self, init=False):
start = datetime.datetime.strptime(
self._runningJobs[job]["start"], "%d-%m-%Y %H:%M:%S"
)
self._runningJobs[job][
"elapsed"
] = "%02d:%02dh:%02dm:%02ds" % convert_duration(
total_seconds(datetime.datetime.today() - start)
self._runningJobs[job]["elapsed"] = (
"%02d:%02dh:%02dm:%02ds"
% convert_duration(total_seconds(datetime.datetime.today() - start))
)

# Loop over the job whose temporary files are still present
Expand Down
Loading

0 comments on commit 897b369

Please sign in to comment.