Skip to content

Commit

Permalink
(core) Created writeDescriptorsToNPY function
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardonpa committed Mar 13, 2024
1 parent 78455db commit 88caf76
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pysipfenn/core/pysipfenn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def writeDescriptorsToCSV(self, descriptor: str, file: str = 'descriptorData.csv
definition file.
Args:
descriptor: Descriptor to use. Must be one of the available descriptors. See ``pysipgenn.descriptorDefinitions``
descriptor: Descriptor to use. Must be one of the available descriptors. See ``pysipfenn.descriptorDefinitions``
for a list of available descriptors, such as ``'KS2022'`` and ``'Ward2017'``. It provides the labels for the
descriptor values.
file: Name of the file to write the results to. If the file already exists, it will be overwritten. If the
Expand All @@ -1061,6 +1061,28 @@ def writeDescriptorsToCSV(self, descriptor: str, file: str = 'descriptorData.csv
f.write(f'{i},{",".join(str(v) for v in dd)}\n')
i += 1

def writeDescriptorsToNPY(self, descriptor: str, file: str = 'descriptorData.npy') -> None:
"""Writes the descriptor data to a numpy file (.NPY). The order of the columns in the numpy array corresponds
to the order of the labels in the descriptor definition files at ``descriptorDefinitions`` directory. To match the
data with the labels, load the labels from the descriptor definition file and use the same index to access the
corresponding data in the numpy array. The order of the rows corresponds to the last run input structures.
Args:
descriptor: Descriptor to use. Must be one of the available descriptors. See ``pysipfenn.descriptorDefinitions``
for a list of available descriptors, such as ``'KS2022'`` and ``'Ward2017'``.
file: Name of the file to write the results to. If the file already exists, it will be overwritten. If the
file does not exist, it will be created. The file must have a ``'.npy'`` extension to be recognized
correctly. Default is ``'descriptorData.npy'``.
"""

# Write descriptor data
if file == 'descriptorData.npy':
print(f"Writing descriptor data to {descriptor}_{file}...")
np.save(f'{descriptor}_descriptorData.npy', self.descriptorData)
else:
print(f"Writing descriptor data to {file}...")
np.save(file, self.descriptorData)

def destroy(self) -> None:
"""Deallocates all loaded models and clears all data from the Calculator object."""
self.loadedModels.clear()
Expand Down

0 comments on commit 88caf76

Please sign in to comment.