Skip to content

Commit

Permalink
Add output dir for histogram in docs and api
Browse files Browse the repository at this point in the history
  • Loading branch information
bobleesj committed Oct 27, 2024
1 parent d18d9d4 commit 3d7d700
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/notebooks/02_cif_ensemble.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
"metadata": {},
"outputs": [],
"source": [
"ensemble = CifEnsemble(Example.ErCoIn_big_folder_path)\n",
"ensemble.generate_structure_histogram()\n",
"ensemble.generate_formula_histogram()\n",
"ensemble.generate_tag_histogram()\n",
Expand All @@ -332,7 +333,15 @@
"ensemble.generate_CN_by_min_dist_method_histogram()\n",
"ensemble.generate_CN_by_best_methods_histogram()\n",
"ensemble.generate_composition_type_histogram()\n",
"ensemble.generate_site_mixing_type_histogram()"
"ensemble.generate_site_mixing_type_histogram()\n",
"\n",
"'''\n",
"# Optional: Specify the output directory where the .png file will be saved.\n",
"ensemble.generate_site_mixing_type_histogram(output_dir=\"path/to/directory\")\n",
"\n",
"# Optional: Call plt.show() to display the histogram on screen.\n",
"ensemble.generate_site_mixing_type_histogram(display=False)\n",
"'''"
]
}
],
Expand Down
165 changes: 165 additions & 0 deletions src/cifkit/models/cif_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,21 @@ def copy_cif_files(
# FIXME: refactor this section to maintain DRY principle

def generate_structure_histogram(self, display=False, output_dir=None):
"""Generate a histogram of the 'structure' property from CIF files.
This method creates a histogram based on the 'structure' statistics of the CIF
files. If 'output_dir' is specified, the histogram image (.png) will be saved to
that directory. If 'output_dir' is not specified, the image will be saved to the
directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"structure",
self.structure_stats,
Expand All @@ -497,6 +512,21 @@ def generate_structure_histogram(self, display=False, output_dir=None):
)

def generate_formula_histogram(self, display=False, output_dir=None):
"""Generate a histogram of the 'formula' property from CIF files.
This method creates a histogram based on the 'formula' statistics of the CIF
files. If 'output_dir' is specified, the histogram image (.png) will be saved to
that directory. If 'output_dir' is not specified, the image will be saved to the
directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"formula",
self.formula_stats,
Expand All @@ -506,6 +536,21 @@ def generate_formula_histogram(self, display=False, output_dir=None):
)

def generate_tag_histogram(self, display=False, output_dir=None):
"""Generate a histogram of the 'tag' property from CIF files.
This method creates a histogram based on the 'tag' statistics of the CIF
files. If 'output_dir' is specified, the histogram image (.png) will be saved to
that directory. If 'output_dir' is not specified, the image will be saved to the
directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"tag",
self.tag_stats,
Expand All @@ -517,6 +562,21 @@ def generate_tag_histogram(self, display=False, output_dir=None):
def generate_space_group_number_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'space_group_number' property from CIF files.
This method creates a histogram based on the 'space_group_number' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"space_group_number",
self.space_group_number_stats,
Expand All @@ -528,6 +588,21 @@ def generate_space_group_number_histogram(
def generate_space_group_name_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'space_group_name' property from CIF files.
This method creates a histogram based on the 'space_group_name' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"space_group_name",
self.space_group_name_stats,
Expand All @@ -539,6 +614,21 @@ def generate_space_group_name_histogram(
def generate_supercell_size_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'supercell_count' property from CIF files.
This method creates a histogram based on the 'supercell_count' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"supercell_size",
self.supercell_size_stats,
Expand All @@ -548,6 +638,21 @@ def generate_supercell_size_histogram(
)

def generate_elements_histogram(self, display=False, output_dir=None):
"""Generate a histogram of the 'unique_elements' property from CIF files.
This method creates a histogram based on the 'unique_elements' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"elements",
self.unique_elements_stats,
Expand All @@ -559,6 +664,21 @@ def generate_elements_histogram(self, display=False, output_dir=None):
def generate_CN_by_min_dist_method_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'CN_by_min' property from CIF files.
This method creates a histogram based on the 'CN_by_min' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"CN_by_min_dist_method",
self.unique_CN_values_by_min_dist_method_stat,
Expand All @@ -570,6 +690,21 @@ def generate_CN_by_min_dist_method_histogram(
def generate_CN_by_best_methods_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'CN_by_best_methods' property from CIF files.
This method creates a histogram based on the 'CN_by_best_methods' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"CN_by_best_methods",
self.unique_CN_values_by_method_methods_stat,
Expand All @@ -581,6 +716,21 @@ def generate_CN_by_best_methods_histogram(
def generate_composition_type_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'composition_type' property from CIF files.
This method creates a histogram based on the 'composition_type' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"composition_type",
self.composition_type_stats,
Expand All @@ -592,6 +742,21 @@ def generate_composition_type_histogram(
def generate_site_mixing_type_histogram(
self, display=False, output_dir=None
):
"""Generate a histogram of the 'site_mixing_type' property from CIF files.
This method creates a histogram based on the 'site_mixing_type' statistics of
the CIF files. If 'output_dir' is specified, the histogram image (.png) will be
saved to that directory. If 'output_dir' is not specified, the image will be saved
to the directory specified by 'self.dir_path'.
Parameters
----------
display : bool, optional
If True, the plot is displayed using plt.show(). Default is False.
output_dir : str, optional
The directory path where the histogram should be saved. If None,
the histogram is saved in the directory defined by 'self.dir_path'.
"""
plot_histogram(
"site_mixing_type",
self.site_mixing_type_stats,
Expand Down

0 comments on commit 3d7d700

Please sign in to comment.