Skip to content

Commit

Permalink
Change name of smact_test function to smact_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavies99 committed May 23, 2019
1 parent 3b191ce commit e39c701
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions docs/examples.rst
Expand Up @@ -93,11 +93,11 @@ combinations. This is a straightforward combinatorial problem of comparing oxida

:math:`\Sigma_i Q_in_i = 0`

where :math:`i` are the elements in the compound and :math:`Q` are the charges. We have a special function, ``smact_test``,
which does this checking for a list of elements. The ``smact_test`` also ensures that all elements specified to be anions
where :math:`i` are the elements in the compound and :math:`Q` are the charges. We have a special function, ``smact_filter``,
which does this checking for a list of elements. The ``smact_filter`` also ensures that all elements specified to be anions
have electronegitivities greater than all elements specified to be cations.

As input ``smact_test`` takes:
As input ``smact_filter`` takes:

* ``els`` : a tuple of the elements to search over (required)
* ``threshold``: the upper limit of the stoichiometric ratios (default = 8)
Expand All @@ -114,7 +114,7 @@ We can look for neutral combos.
# We just want the element items from the dictionary
eles = [e[1] for e in space.items()]
# We set a threshold for the stoichiometry of 4
allowed_combinations = smact.screening.smact_test(eles, threshold=4)
allowed_combinations = smact.screening.smact_filter(eles, threshold=4)
print(allowed_combinations)
[(('Ti', 'Al', 'O'), (1, 3, 3)),
Expand Down
8 changes: 4 additions & 4 deletions examples/Counting/Generate_compositions_lists.ipynb
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Generate a list of SMACT-allowed compositions\n",
"This notebook provides a short demo of how to use SMACT to generate a list of element compositions that could later be used as input for machine learning or some other screening workflow. \n",
"We use the standard `smact_test` as described in the [docs](https://smact.readthedocs.io/en/latest/examples.html#neutral-combinations) and outlined more fully in [this research paper](https://www.ncbi.nlm.nih.gov/pubmed/27790643).\n",
"We use the standard `smact_filter` as described in the [docs](https://smact.readthedocs.io/en/latest/examples.html#neutral-combinations) and outlined more fully in [this research paper](https://www.ncbi.nlm.nih.gov/pubmed/27790643).\n",
"\n",
"In the example below, we generate ternary oxide compositions of the first row transition metals."
]
Expand All @@ -19,7 +19,7 @@
"source": [
"### Imports\n",
"from smact import Element, element_dictionary, ordered_elements\n",
"from smact.screening import smact_test\n",
"from smact.screening import smact_filter\n",
"from datetime import datetime\n",
"import itertools\n",
"import multiprocessing"
Expand Down Expand Up @@ -150,11 +150,11 @@
}
],
"source": [
"# Use multiprocessing and smact_test to quickly generate our list of compositions\n",
"# Use multiprocessing and smact_filter to quickly generate our list of compositions\n",
"start = datetime.now()\n",
"if __name__ == '__main__': # Always use pool protected in an if statement \n",
" with multiprocessing.Pool(processes=4) as p: # start 4 worker processes\n",
" result = p.map(smact_test, ternary_systems)\n",
" result = p.map(smact_filter, ternary_systems)\n",
"print('Time taken to generate list: {0}'.format(datetime.now()-start))"
]
},
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Expand Up @@ -22,7 +22,7 @@ These examples also explore the generation of compositional spaces:

- **Generate\_compositions\_lists.ipynb:** A walkthrough of how to use SMACT to generate a list
of allowed compositions from a chosen search-space of elements. It shows how to choose the elements
you are interested in, and how to apply the standard smact_test with a certain stoichiometry threshold (see [docs here](https://smact.readthedocs.io/en/latest/examples.html#neutral-combinations) for more info).
you are interested in, and how to apply the standard smact_filter with a certain stoichiometry threshold (see [docs here](https://smact.readthedocs.io/en/latest/examples.html#neutral-combinations) for more info).
It also shows you how to interface the output to [Pymatgen](http://pymatgen.org/) or [Pandas](https://pandas.pydata.org/).

- **Raw_combinations.ipynb:** Does not use SMACT, but uses itertools to calculate the raw number of possible
Expand Down Expand Up @@ -53,9 +53,9 @@ These rules allow us to estimate whether or not a perovskite structure is likely
We also apply the standard charge neutrality and electronegativity tests as described [in the docs](https://smact.readthedocs.io/en/latest/examples.html#neutral-combinations).

### Solar oxides
Generates a set of quaternary oxide compositions using a modified `smact_test` function and then turns the results into a dataframe with features that can be read by a machine learning algorithm.
Generates a set of quaternary oxide compositions using a modified `smact_filter` function and then turns the results into a dataframe with features that can be read by a machine learning algorithm.

### Simple wrappers

Gives a simple example of how SMACT can be incorporated into a python script
for use at the command line using argparse.
for use at the command line using argparse.
6 changes: 3 additions & 3 deletions examples/Solar_oxides/SolarOxides.ipynb
Expand Up @@ -5,7 +5,7 @@
"metadata": {},
"source": [
"## Composition generation\n",
"Here, we generate a set of quaternary oxide compositions using a modified `smact_test` function and then turn the results into a dataframe with features that can be read by a machine learning algorithm.\n"
"Here, we generate a set of quaternary oxide compositions using a modified `smact_filter` function and then turn the results into a dataframe with features that can be read by a machine learning algorithm.\n"
]
},
{
Expand Down Expand Up @@ -43,7 +43,7 @@
"\n",
"all_el_combos = combinations(good_elements,3)\n",
"\n",
"def smact_test(els):\n",
"def smact_filter(els):\n",
" all_compounds = []\n",
" elements = [e.symbol for e in els] + ['O']\n",
" \n",
Expand Down Expand Up @@ -88,7 +88,7 @@
],
"source": [
"with multiprocessing.Pool() as p:\n",
" result = p.map(smact_test, all_el_combos)\n",
" result = p.map(smact_filter, all_el_combos)\n",
" \n",
"flat_list = [item for sublist in result for item in sublist]\n",
"print(\"Number of compositions: {0}\".format(len(flat_list)))"
Expand Down
2 changes: 1 addition & 1 deletion smact/screening.py
Expand Up @@ -286,7 +286,7 @@ def ml_rep_generator(composition, stoichs=None):
norm = [float(i)/sum(ML_rep) for i in ML_rep]
return norm

def smact_test(els, threshold=8, species_unique=True):
def smact_filter(els, threshold=8, species_unique=True):
"""Function that applies the charge neutrality and electronegativity
tests in one go for simple application in external scripts that
wish to apply the general 'smact test'.
Expand Down
6 changes: 3 additions & 3 deletions smact/tests/test.py
Expand Up @@ -189,14 +189,14 @@ def test_ml_rep_generator(self):
[Pb, O], [1, 2]), PbO2_ml
)

def test_smact_test(self):
def test_smact_filter(self):
Na, Fe, Cl = (smact.Element(label) for label in ('Na', 'Fe', 'Cl'))
self.assertEqual(smact.screening.smact_test(
self.assertEqual(smact.screening.smact_filter(
[Na, Fe, Cl], threshold=2),
[(('Na', 'Fe', 'Cl'), (1, -1, -1), (2, 1, 1)),
(('Na', 'Fe', 'Cl'), (1, 1, -1), (1, 1, 2))]
)
self.assertEqual(len(smact.screening.smact_test(
self.assertEqual(len(smact.screening.smact_filter(
[Na, Fe, Cl], threshold=8)), 77
)

Expand Down

0 comments on commit e39c701

Please sign in to comment.