-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added vector_to_formula class method
- Loading branch information
1 parent
d096cd4
commit 24b2db3
Showing
2 changed files
with
33 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
__copyright__ = "2019, Cameron Hargreaves" | ||
__credits__ = ["https://github.com/Zapaan", "Loïc Séguin-C. <[email protected]>", "https://github.com/Bowserinator/"] | ||
__license__ = "GPL" | ||
__version__ = "0.5.11" | ||
__version__ = "0.5.12" | ||
''' | ||
import json | ||
|
@@ -55,12 +55,34 @@ def main(): | |
print(x.elmd(y)) | ||
print(y.elmd(x)) | ||
|
||
print(x.pretty_formula) | ||
print(x.vec_to_formula(x.feature_vector)) | ||
print(y.vec_to_formula(x.feature_vector)) | ||
print(x.vec_to_formula(y.feature_vector)) | ||
|
||
x = ElMD("CaTiO3", metric="fast") | ||
y = ElMD("NaCl", metric="fast") | ||
|
||
print(x.elmd(y)) | ||
print(y.elmd(x)) | ||
|
||
print(x.pretty_formula) | ||
print(x.vec_to_formula(x.feature_vector)) | ||
print(y.vec_to_formula(x.feature_vector)) | ||
print(x.vec_to_formula(y.feature_vector)) | ||
|
||
x = ElMD("CaTiO3", metric="mendeleev") | ||
y = ElMD("NaCl", metric="mendeleev") | ||
|
||
print(x.elmd(y)) | ||
print(y.elmd(x)) | ||
|
||
print(x.pretty_formula) | ||
print(x.vec_to_formula(x.feature_vector)) | ||
print(y.vec_to_formula(x.feature_vector)) | ||
print(x.vec_to_formula(y.feature_vector)) | ||
|
||
|
||
print(time.time() - ts) | ||
|
||
@lru_cache(maxsize=16) | ||
|
@@ -178,7 +200,7 @@ def __init__(self, formula="", metric="mod_petti", strict_parsing=False, x=1): | |
self.ratio_vector = self._gen_ratio_vector() | ||
self.petti_vector = self._gen_petti_vector() | ||
|
||
self.pretty_formula = self._gen_pretty() | ||
self.pretty_formula = self.vec_to_formula() | ||
|
||
self.feature_vector = self._gen_feature_vector() | ||
|
||
|
@@ -343,18 +365,21 @@ def _gen_feature_vector(self): | |
|
||
return weighted_vector | ||
|
||
def _gen_pretty(self): | ||
def vec_to_formula(self, vector=None): | ||
''' | ||
Return a normalized formula string ordered by the mod_petti dictionary | ||
''' | ||
inds = np.where(self.petti_vector != 0.0)[0] | ||
if vector is None: | ||
vector = self.petti_vector | ||
|
||
inds = np.where(vector != 0.0)[0] | ||
pretty_form = "" | ||
|
||
for i, ind in enumerate(inds): | ||
if self.petti_vector[ind] == 1: | ||
if vector[ind] == 1: | ||
pretty_form = pretty_form + f"{self.lookup[ind]}" | ||
else: | ||
pretty_form = pretty_form + f"{self.lookup[ind]}{self.petti_vector[ind]:.3f}".strip('0') + ' ' | ||
pretty_form = pretty_form + f"{self.lookup[ind]}{vector[ind]:.3f}".strip('0') + ' ' | ||
|
||
return pretty_form.strip() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,13 @@ | |
setup( | ||
name = 'ElMD', | ||
packages = ['ElMD'], | ||
<<<<<<< HEAD | ||
version = '0.5.5', | ||
======= | ||
version = '0.5.4', | ||
>>>>>>> 0c4ba033856e760ba89e61b5390c791bff7be88f | ||
version = '0.5.12', | ||
license='GPL3', | ||
description = 'An implementation of the Element movers distance for chemical similarity of ionic compositions', | ||
author = 'Cameron Hagreaves', | ||
author_email = '[email protected]', | ||
url = 'https://github.com/lrcfmd/ElMD/', | ||
<<<<<<< HEAD | ||
download_url = 'https://github.com/lrcfmd/ElMD/archive/v0.5.5.tar.gz', | ||
======= | ||
download_url = 'https://github.com/lrcfmd/ElMD/archive/v0.5.4.tar.gz', | ||
>>>>>>> 0c4ba033856e760ba89e61b5390c791bff7be88f | ||
download_url = 'https://github.com/lrcfmd/ElMD/archive/v0.5.12.tar.gz', | ||
keywords = ['ChemInformatics', 'Materials Science', 'Machine Learning', 'Materials Representation'], | ||
package_data={"elementFeatures": ["el_lookup/*.json"]}, | ||
include_package_data=True, | ||
|