Skip to content

Commit

Permalink
Run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
oerc0122 committed Feb 5, 2025
1 parent 85abb15 commit 34f4106
Show file tree
Hide file tree
Showing 182 changed files with 841 additions and 1,863 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
- uses: astral-sh/ruff-action@v3
with:
options: "--check --verbose"
src: "MDANSE_GUI/Src"
src: "./MDANSE/Src"
args: "format --check"

lint_check_ruff:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Doc/conf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""
"""
Created on Mar 30, 2015
@author: Gael Goret and Eric C. Pellegrini
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Doc/conf_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""
"""
Created on Mar 30, 2015
@author: Gael Goret and Eric C. Pellegrini
Expand Down
13 changes: 3 additions & 10 deletions MDANSE/Src/MDANSE/Chemistry/ChemicalSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


class ChemicalSystem:

def __init__(self, name: str = "", trajectory=None):
"""
Expand Down Expand Up @@ -80,9 +79,7 @@ def add_atom(self, atm_num: int) -> int:
def add_bonds(self, pair_list: List[Tuple[int]]):
self._bonds += list(pair_list)
for pair in pair_list:
self.rdkit_mol.AddBond(
int(pair[0]), int(pair[1]), Chem.rdchem.BondType.UNSPECIFIED
)
self.rdkit_mol.AddBond(int(pair[0]), int(pair[1]), Chem.rdchem.BondType.UNSPECIFIED)

def add_labels(self, label_dict: Dict[str, List[int]]):
for key, item in label_dict.items():
Expand All @@ -98,9 +95,7 @@ def add_clusters(self, group_list: List[List[int]]):
continue
atom_list = [self._atom_types[index] for index in group]
unique_atoms, counts = np.unique(atom_list, return_counts=True)
name = "_".join(
[str(unique_atoms[n]) + str(counts[n]) for n in range(len(counts))]
)
name = "_".join([str(unique_atoms[n]) + str(counts[n]) for n in range(len(counts))])
if name not in self._clusters:
self._clusters[name] = [sorted_group]
else:
Expand All @@ -122,9 +117,7 @@ def has_substructure_match(self, smarts: str) -> bool:
"""
return self.rdkit_mol.HasSubstructMatch(Chem.MolFromSmarts(smarts))

def get_substructure_matches(
self, smarts: str, maxmatches: int = 1000000
) -> set[int]:
def get_substructure_matches(self, smarts: str, maxmatches: int = 1000000) -> set[int]:
"""Get the indices which match the smarts string. Note that
the default bond type in MDANSE is
Chem.rdchem.BondType.UNSPECIFIED.
Expand Down
29 changes: 7 additions & 22 deletions MDANSE/Src/MDANSE/Chemistry/Databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ def add_atom(self, atom: str) -> None:
"""

if atom in self._data:
raise AtomsDatabaseError(
"The atom {} is already stored in the database".format(atom)
)
raise AtomsDatabaseError("The atom {} is already stored in the database".format(atom))

self._data[atom] = {}

Expand Down Expand Up @@ -304,9 +302,7 @@ def get_isotopes(self, atom: str) -> list[str]:
# The isotopes are searched according to |symbol| property
symbol = self._data[atom]["symbol"]

return [
iname for iname, props in self._data.items() if props["symbol"] == symbol
]
return [iname for iname, props in self._data.items() if props["symbol"] == symbol]

@property
def properties(self) -> list[str]:
Expand Down Expand Up @@ -338,8 +334,7 @@ def get_property(self, pname: str) -> dict[str, Union[str, int, float, list]]:
ptype = AtomsDatabase._TYPES[self._properties[pname]]

return {
element: properties.get(pname, ptype())
for element, properties in self._data.items()
element: properties.get(pname, ptype()) for element, properties in self._data.items()
}

def get_value(self, atom: str, pname: str) -> Union[str, int, float, list]:
Expand Down Expand Up @@ -400,9 +395,7 @@ def get_values_for_multiple_atoms(
values = {name: self._data[name][prop] for name in unique_atoms}
return [values[atom] for atom in atoms]

def set_value(
self, atom: str, pname: str, value: Union[str, int, float, list]
) -> None:
def set_value(self, atom: str, pname: str, value: Union[str, int, float, list]) -> None:
"""
Set the given property of the given atom to the given value.
Expand All @@ -425,9 +418,7 @@ def set_value(
)

try:
self._data[atom][pname] = AtomsDatabase._TYPES[self._properties[pname]](
value
)
self._data[atom][pname] = AtomsDatabase._TYPES[self._properties[pname]](value)
except ValueError:
raise AtomsDatabaseError(
"Can not coerce {} to {} type".format(value, self._properties[pname])
Expand Down Expand Up @@ -482,9 +473,7 @@ def info(self, atom: str) -> str:

# The values for all element's properties
for pname in sorted(self._properties):
info.append(
" {0:<20}{1:>50}".format(pname, str(self._data[atom].get(pname, None)))
)
info.append(" {0:<20}{1:>50}".format(pname, str(self._data[atom].get(pname, None))))

info.append(delimiter)
info = "\n".join(info)
Expand Down Expand Up @@ -564,11 +553,7 @@ def numeric_properties(self) -> list[str]:
:return: the name of the numeric properties stored in the atoms database
:rtype: list
"""
return [
pname
for pname, prop in self._properties.items()
if prop in ["int", "float"]
]
return [pname for pname, prop in self._properties.items() if prop in ["int", "float"]]

def _reset(self) -> None:
"""
Expand Down
8 changes: 2 additions & 6 deletions MDANSE/Src/MDANSE/Core/Platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,7 @@ def etime_to_ctime(self, etime):

days, hours, minutes, seconds = etime[-4:]

etime = datetime.timedelta(
days=days, hours=hours, minutes=minutes, seconds=seconds
)
etime = datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)

return (datetime.datetime.today() - etime).strftime("%d-%m-%Y %H:%M:%S")

Expand All @@ -457,9 +455,7 @@ def get_processes_info(self):
procs = [p.split() for p in procs if p]

# A mapping between the active processes pid and their corresponding exectuable.
procs = dict(
[(int(p[0].strip()), self.etime_to_ctime(p[1].strip())) for p in procs]
)
procs = dict([(int(p[0].strip()), self.etime_to_ctime(p[1].strip())) for p in procs])

return procs

Expand Down
4 changes: 1 addition & 3 deletions MDANSE/Src/MDANSE/Core/Singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def __call__(self, *args, **kwargs):
"""

if self.__name__ not in self.__instances:
self.__instances[self.__name__] = super(Singleton, self).__call__(
*args, **kwargs
)
self.__instances[self.__name__] = super(Singleton, self).__call__(*args, **kwargs)

return self.__instances[self.__name__]
7 changes: 2 additions & 5 deletions MDANSE/Src/MDANSE/Core/SubclassFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def recursive_search(parent_class: type, name: str):
return return_type
else:
for child in parent_class._registered_subclasses.keys():
return_type = recursive_search(
parent_class._registered_subclasses[child], name
)
return_type = recursive_search(parent_class._registered_subclasses[child], name)
if return_type is not None:
return return_type

Expand Down Expand Up @@ -114,8 +112,7 @@ def recursive_dict(parent_class: type) -> dict:
"""
try:
results = {
ckey: parent_class._registered_subclasses[ckey]
for ckey in parent_class.subclasses()
ckey: parent_class._registered_subclasses[ckey] for ckey in parent_class.subclasses()
}
except Exception:
return {}
Expand Down
9 changes: 2 additions & 7 deletions MDANSE/Src/MDANSE/Framework/AtomMapping/atom_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class AtomLabel:

def __init__(self, atm_label: str, **kwargs):
"""Creates an atom label object which is used for atom mapping
and atom type guessing.
Expand Down Expand Up @@ -171,9 +170,7 @@ def guess_element(atm_label: str, mass: Union[float, int, None] = None) -> str:
raise AttributeError(f"Unable to guess: {atm_label}")


def get_element_from_mapping(
mapping: dict[str, dict[str, str]], label: str, **kwargs
) -> str:
def get_element_from_mapping(mapping: dict[str, dict[str, str]], label: str, **kwargs) -> str:
"""Determine the symbol of the element from the atom label and
the information from the kwargs.
Expand Down Expand Up @@ -202,9 +199,7 @@ def get_element_from_mapping(
return element


def fill_remaining_labels(
mapping: dict[str, dict[str, str]], labels: list[AtomLabel]
) -> None:
def fill_remaining_labels(mapping: dict[str, dict[str, str]], labels: list[AtomLabel]) -> None:
"""Given a list of labels fill the remaining labels in the mapping
dictionary.
Expand Down
12 changes: 2 additions & 10 deletions MDANSE/Src/MDANSE/Framework/AtomSelector/all_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from MDANSE.MolecularDynamics.Trajectory import Trajectory


def select_all(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_all(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects all atoms in the chemical system except for the dummy
atoms.
Expand All @@ -45,10 +43,4 @@ def select_all(
for atm in system._unique_elements:
if trajectory.get_atom_property(atm, "dummy"):
dummy_list.append(atm)
return set(
[
index
for index in system._atom_indices
if atom_list[index] not in dummy_list
]
)
return set([index for index in system._atom_indices if atom_list[index] not in dummy_list])
18 changes: 4 additions & 14 deletions MDANSE/Src/MDANSE/Framework/AtomSelector/atom_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def select_element(
return system.get_substructure_matches(pattern)


def select_dummy(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_dummy(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects all dummy atoms in the chemical system.
Parameters
Expand Down Expand Up @@ -86,11 +84,7 @@ def select_dummy(
if trajectory.get_atom_property(atm, "dummy"):
dummy_list.append(atm)
return set(
[
index
for index, element in enumerate(system.atom_list)
if element in dummy_list
]
[index for index, element in enumerate(system.atom_list) if element in dummy_list]
)


Expand Down Expand Up @@ -119,9 +113,7 @@ def select_atom_name(
return True
return False
else:
return set(
[index for index, element in enumerate(system.atom_list) if element == name]
)
return set([index for index, element in enumerate(system.atom_list) if element == name])


def select_atom_fullname(
Expand Down Expand Up @@ -149,9 +141,7 @@ def select_atom_fullname(
return True
return False
else:
return set(
[index for index, name in enumerate(system.name_list) if name == fullname]
)
return set([index for index, name in enumerate(system.name_list) if name == fullname])


def select_hs_on_element(
Expand Down
20 changes: 5 additions & 15 deletions MDANSE/Src/MDANSE/Framework/AtomSelector/group_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def select_primary_amine(
return system.get_substructure_matches(pattern)


def select_hydroxy(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_hydroxy(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects the O and H atoms of all hydroxy groups including water.
Parameters
Expand All @@ -77,9 +75,7 @@ def select_hydroxy(
return system.get_substructure_matches(pattern)


def select_methyl(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_methyl(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects the C and H atoms of all methyl groups.
Parameters
Expand All @@ -102,9 +98,7 @@ def select_methyl(
return system.get_substructure_matches(pattern)


def select_phosphate(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_phosphate(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects the P and O atoms of all phosphate groups.
Parameters
Expand All @@ -127,9 +121,7 @@ def select_phosphate(
return system.get_substructure_matches(pattern)


def select_sulphate(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_sulphate(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects the S and O atoms of all sulphate groups.
Parameters
Expand All @@ -152,9 +144,7 @@ def select_sulphate(
return system.get_substructure_matches(pattern)


def select_thiol(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_thiol(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects the S and H atoms of all thiol groups.
Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
]


def select_water(
trajectory: Trajectory, check_exists: bool = False
) -> Union[set[int], bool]:
def select_water(trajectory: Trajectory, check_exists: bool = False) -> Union[set[int], bool]:
"""Selects the O and H atoms of all water molecules.
Parameters
Expand Down
Loading

0 comments on commit 34f4106

Please sign in to comment.