Skip to content

Commit

Permalink
DEV: linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
qchempku2017 committed Sep 14, 2023
1 parent fc8ea5d commit f034917
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ repos:
additional_dependencies:
- flake8-typing-imports==1.10.1
- flake8-rst==0.8.0
- Flake8-pyproject

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0 # pick a git hash / tag to point to
Expand Down
3 changes: 3 additions & 0 deletions WFacer/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def compare_min_energy_structures_by_composition(min_e1, min_e2, matcher=None):
matcher (StructureMatcher): optional
A StructureMatcher used compare structures.
wrangler.cluster_subspace._site_matcher is recommended.
Return:
float, bool:
maximum energy difference in eV/site,
Expand Down Expand Up @@ -52,6 +53,7 @@ def compare_fitted_coefs(cluster_subspace, coefs_prev, coefs_now):
Not ECIs because not divided by multiplicity!
coefs_now(1d arrayLike):
Cluster coefficients fitted in the latest iteration.
Returns:
float:
|| ECI' - ECI ||_1 / ||ECI||_1.
Expand Down Expand Up @@ -83,6 +85,7 @@ def ce_converged(
must be equal to that of current iter_id - 1.
convergence_options(dict):
Pre-processed convergence criterion.
Returns:
bool.
"""
Expand Down
4 changes: 4 additions & 0 deletions WFacer/enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def enumerate_matrices(
to 30, to prevent over-skewing.
kwargs:
keyword arguments to pass into SpaceGroupAnalyzer.
Returns:
List of 2D lists.
"""
Expand Down Expand Up @@ -222,6 +223,7 @@ def enumerate_compositions_as_counts(
Results will be returned in "counts" format
(see smol.moca.CompositionSpace).
Args:
sc_size(int):
The super-cell size in the number of prim cells.
Expand All @@ -239,6 +241,7 @@ def enumerate_compositions_as_counts(
Default to 1.
kwargs:
Other keyword arguments to initialize CompositionSpace.
Returns:
Enumerated possible compositions in "counts" format, not normalized:
2D np.ndarray[int]
Expand Down Expand Up @@ -427,6 +430,7 @@ def generate_training_structures(
before matching. It should be used with caution.
kwargs:
Keyword arguments for utils.selection.select_initial_rows.
Returns:
list[Structure], list[3*3 list[list[int]]], list[list[float]]:
Initial training structures, super-cell matrices,
Expand Down
2 changes: 2 additions & 0 deletions WFacer/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def fit_ecis_from_wrangler(
"""Fit ECIs from a fully processed wrangler.
No weights will be used.
Args:
wrangler(CeDataWrangler):
A CeDataWrangler storing all training structures.
Expand Down Expand Up @@ -60,6 +61,7 @@ def fit_ecis_from_wrangler(
Other keyword arguments to initialize an optimizer.
kwargs:
Keyword arguments used by estimator._fit. For example, solver arguments.
Returns:
Estimator, 1D np.ndarray, float, float, float, 1D np.ndarray:
Fitted estimator, coefficients (not ECIs), cross validation error (meV/site),
Expand Down
7 changes: 7 additions & 0 deletions WFacer/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def enumerate_structures(last_ce_document):
Args:
last_ce_document(CeOutputsDocument):
The last cluster expansion outputs document.
Returns:
dict:
Newly enumerated structures, super-cell matrices
Expand Down Expand Up @@ -266,6 +267,7 @@ def get_structure_calculation_flows(enum_output, last_ce_document):
Output by enumeration job.
last_ce_document(CeOutputsDocument):
The last cluster expansion outputs document.
Returns:
list[Flow], list[OutputReference]:
Flows for each structure and their output references pointing
Expand Down Expand Up @@ -325,6 +327,7 @@ def calculate_structures_job(enum_output, last_ce_document):
Output by enumeration job.
last_ce_document(CeOutputsDocument):
The last cluster expansion outputs document.
Returns:
list[TaskDoc]:
Results of VASP calculations as TaskDoc.
Expand Down Expand Up @@ -353,6 +356,7 @@ def parse_calculations(taskdocs, enum_output, last_ce_document):
Output by enumeration job.
last_ce_document(CeOutputsDocument):
The last cluster expansion outputs document.
Returns:
dict
Updated wrangler, all entries before decoration,
Expand Down Expand Up @@ -471,6 +475,7 @@ def fit_calculations(parse_output, last_ce_document):
Output by parse job.
last_ce_document(CeOutputsDocument):
The last cluster expansion outputs document.
Returns:
dict:
Dictionary containing fitted CE information.
Expand Down Expand Up @@ -506,6 +511,7 @@ def update_document(enum_output, parse_output, fit_output, last_ce_document):
Output by parse job.
last_ce_document(CeOutputsDocument):
The last cluster expansion outputs document.
Returns:
CeOutputDocument:
The updated document.
Expand Down Expand Up @@ -550,6 +556,7 @@ def initialize_document(prim, project_name="ace-work", options=None):
In this job, a cluster subspace will be created, super-cells
and compositions will also be enumerated.
Args:
prim(structure):
A primitive cell structure (no need to be reduced) with
Expand Down
2 changes: 2 additions & 0 deletions WFacer/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def ce_step_trigger(last_ce_document):
last_ce_document(CeOutputsDocument):
The cluster expansion outputs document from the
latest step.
Returns:
Response:
Either a CeOutputsDocument if converged, or a
Expand Down Expand Up @@ -120,6 +121,7 @@ def make(self, prim, last_document=None, add_num_iterations=None):
number of iterations, add this many more iterations.
Default is None. When given None or 0, will simply double
max_iter in options.
Returns:
Flow:
The iterative cluster expansion workflow.
Expand Down
12 changes: 12 additions & 0 deletions WFacer/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def reduce_prim(prim, **kwargs):
A primitive cell with partial occupancy to be expanded.
kwargs:
Keyword arguments for SpacegroupAnalyzer.
Returns:
Structure
"""
Expand Down Expand Up @@ -168,6 +169,7 @@ def get_cluster_subspace(
for extensibility.)
kwargs:
Other keyword arguments for ClusterSubspace.from_cutoffs.
Returns:
ClusterSubspace:
A cluster subspace generated from cutoffs.
Expand All @@ -194,6 +196,7 @@ def process_supercell_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing supercell matrix options, including the following keys:
Expand Down Expand Up @@ -246,6 +249,7 @@ def process_composition_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing composition options, including the following keys:
Expand Down Expand Up @@ -321,6 +325,7 @@ def process_structure_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing structure options, including the following keys:
Expand Down Expand Up @@ -377,6 +382,7 @@ def process_calculation_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing calculation options, including the following keys:
Expand Down Expand Up @@ -459,6 +465,7 @@ def process_decorator_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing calculation options, including the following keys:
Expand Down Expand Up @@ -509,6 +516,7 @@ def process_subspace_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing fit options, including the following keys:
Expand Down Expand Up @@ -541,6 +549,7 @@ def process_fit_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing fit options, including the following keys:
Expand Down Expand Up @@ -603,6 +612,7 @@ def process_convergence_options(d):
Args:
d(dict):
An input dictionary containing various options in the input file.
Returns:
dict:
A dict containing convergence options, including the following keys:
Expand Down Expand Up @@ -658,9 +668,11 @@ def get_initial_ce_coefficients(cluster_subspace):
Any coefficient, except those for external terms, will be initialized to 0.
This guarantees that for ionic systems, structures with lower ewald energy
are always selected first.
Args:
cluster_subspace(ClusterSubspace):
The initial cluster subspace.
Returns:
np.ndarray[float].
"""
Expand Down
13 changes: 12 additions & 1 deletion WFacer/specie_decorators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def group_site_by_species(entries):
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Return:
(Entry index, site index) occupied by each species:
defaultdict
Expand All @@ -125,6 +126,7 @@ def is_trained(self):
"""Gives whether this decorator is trained before.
If trained, will be blocked from training again.
Returns:
bool.
"""
Expand Down Expand Up @@ -154,9 +156,11 @@ def decorate(self, entries):
If an assigned entry is not valid,
for example, in charge assignment, if an assigned structure is not
charge neutral, then this entry will be returned as None.
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Returns:
List[NoneType|ComputedStructureEntry]
"""
Expand Down Expand Up @@ -422,9 +426,11 @@ def decorate(self, entries):
If an assigned entry is not valid,
for example, in charge assignment, if an assigned structure is not
charge neutral, then this entry will be returned as None.
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Returns:
Entries with structures decorated. Returns None if decoration
failed (not charge balanced, etc.)
Expand Down Expand Up @@ -515,7 +521,7 @@ def __init__(self, labels, cuts=None, **kwargs):
GuessChargeDecorator.
Be sure to provide labels for all the species you wish to assign
a property to, otherwise, you are the cause of your own error!
cuts(dict{str|Species: list}): optional
cuts(dict{str|Species: list}): optional
Cuts to divide required property value into sectors, so as
to decide the label they belong to. Keys are the same
as argument "labels".
Expand Down Expand Up @@ -547,6 +553,7 @@ def is_trained(self):
"""Gives whether this decorator is trained before.
If trained, will be blocked from training again.
Returns:
bool.
"""
Expand Down Expand Up @@ -657,6 +664,7 @@ def train(self, entries, reset=False, n_calls=50):
First initialize with mixture of gaussian, then
optimize some objective function with gaussian process.
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Expand Down Expand Up @@ -707,9 +715,11 @@ def decorate(self, entries):
If an assigned entry is not valid,
for example, in charge assignment, if an assigned structure is not
charge neutral, then this entry will be returned as None.
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Returns:
List[NoneType|ComputedStructureEntry]
"""
Expand Down Expand Up @@ -796,6 +806,7 @@ def get_site_property_query_names_from_decorator(decname):
Args:
decname(str):
Decorator name.
Returns:
list[str]:
List of names of required site properties by the
Expand Down
4 changes: 4 additions & 0 deletions WFacer/specie_decorators/charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def decorate(self, entries):
Warning: Do not use this with multi-valent
elements, unless you know what you want
clearly!!!
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Returns:
List[NoneType|ComputedStructureEntry]
"""
Expand Down Expand Up @@ -143,9 +145,11 @@ def decorate(self, entries):
Warning: Do not use this with multi-valent
elements, unless you know what you want
clearly!!!
Args:
entries(List[ComputedStructureEntry]):
Entries of computed structures.
Returns:
List[NoneType|ComputedStructureEntry]
"""
Expand Down
1 change: 1 addition & 0 deletions WFacer/utils/convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_min_energy_structures_by_composition(wrangler, max_iter_id=None):
max_iter_id(int): optional
Maximum iteration index included in the energy comparison.
If none given, will read existing maximum iteration number.
Returns:
defaultdict:
element compositions as keys, energy per site and structure
Expand Down
4 changes: 4 additions & 0 deletions WFacer/utils/duplicacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ def clean_up_decoration(s):
"""Remove all decoration from a structure.
Used before comparing two structures before sending to compute.
Args:
s(Structure):
A structure.
Returns:
Structure:
The cleaned up structure containing only Element.
Expand Down Expand Up @@ -55,6 +57,7 @@ def is_duplicate(s1, s2, remove_decorations=False, matcher=None):
matcher(StructureMatcher): optional
A StructureMatcher to compare two structures. Using the same
_site_matcher as cluster_subspace is highly recommended.
Returns:
bool
"""
Expand All @@ -80,6 +83,7 @@ def is_corr_duplicate(s1, proc1, s2=None, proc2=None, features2=None):
faster that comparing two structures, because comparing two
structures might involve reducing them to primitive cells
in advance, which can occasionally be very slow.
Args:
s1 (Structure):
A structure to be checked.
Expand Down
1 change: 1 addition & 0 deletions WFacer/utils/occu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def get_random_occupancy_from_counts(ensemble, counts):
counts(1D arrayLike):
Species composition in "counts" format.
See smol.moca.composition.
Returns:
np.ndarray:
An encoded occupancy array.
Expand Down
Loading

0 comments on commit f034917

Please sign in to comment.