From 88caf7686b0731eff6073fe6cd205e8e66d92029 Mon Sep 17 00:00:00 2001 From: rdamaral Date: Wed, 13 Mar 2024 17:14:55 -0400 Subject: [PATCH] (core) Created writeDescriptorsToNPY function --- pysipfenn/core/pysipfenn.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pysipfenn/core/pysipfenn.py b/pysipfenn/core/pysipfenn.py index 224e89e..70ca37b 100644 --- a/pysipfenn/core/pysipfenn.py +++ b/pysipfenn/core/pysipfenn.py @@ -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 @@ -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()