<jupyter_start><jupyter_text>Example Runthrough of Our PackageThe following notebook demonstrates the usage of the functions available when downloading teh `kratosbat` package. We will show how to extract data from the materials project and then further analyze it and predict outcomes using multiple statistical and machine learning methods.  Extracting data from materialsproject.orgWe will first import some relevant modules required for extracting data from the materialsproject.org. The submodule for any data extraction methods is known as `data_extract`:<jupyter_code>import data_extract
import pandas as pd<jupyter_output><empty_output><jupyter_text>The `get_bat_dat` function is able to mine the entire materials project for all materials classified as battery materials and will return a dataframe of all battery materials and their properties. *NOTE* The function takes an API key as an input to access the materialsproject database. We suggest generating your own API key from the dashboard of materials project.<jupyter_code>data_extract.get_bat_dat('EcOxTpa0ymKFe24R')<jupyter_output><empty_output><jupyter_text>This function also saves this data as a .csv file called **BatteryData.csv**. This data is also cached in the repository as the `get_bat_dat` function can take over 30 minutes to run as it loops through over 4000 battery materials. Therefore, it may be more convenient to read the given .csv file as shown below.<jupyter_code>df = pd.read_csv('BatteryData.csv')
df<jupyter_output><empty_output><jupyter_text>We are aware that the materials project is constantly adding materials to its database. To check to see if the cached .csv file is up to date with that available at materialsproject.org, we can simply use the `update_check` function available in the `data_extract` module. Again, this function requires an API key.<jupyter_code>data_extract.update_check('EcOxTpa0ymKFe24R')<jupyter_output>The Current BatteryData.csv file is up to date!<jupyter_text>Neural Network<jupyter_code>import predict_tools
import torch
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>The neural network that we developed utilizes ``PyTorch`` for creation of the model, as well as the forward and backpropogation techniques to properly train the neural network. We will import our ``predict_tools`` to have all the functions we need henceforth. Now, we will create a model to predict volumetric and gravimetric capacity based off the information from **materialsproject.org**, normalized using our PCA process. The function takes a dataframe, the number of inputs, the size of the first, then second, hidden layer, and the number of outputs. The final parameter is the number of datapoints that we will use in our model.<jupyter_code>model = predict_tools.nn_capacity('NEWMinMaxScaler.csv', 91, 100, 75, 2, 4000)<jupyter_output><empty_output><jupyter_text>If we look at our output:<jupyter_code>model<jupyter_output><empty_output><jupyter_text>We see that it is a PyTorch model! Let's predict some data now.First, we will create a dataframe that takes some information from the **materialsproject.org** database:<jupyter_code>train_bat = pd.read_csv('NEWMinMaxScaler.csv')

x_train = train_bat.drop(columns=['Unnamed: 0', 'Gravimetric Capacity (units)', 'Volumetric Capacity', 'Max Delta Volume'])

x_test = np.array(x_train[4000:])
x_test = torch.tensor(x_test, dtype = torch.float)
predict_tools.get_predictions(model, x_test)<jupyter_output><empty_output><jupyter_text>For the user To generate the information needed for the Neural Network, users must use the ``generate_inputs`` Python function: The user just needs to input their working ion, crystal system number, spacegroup number, charge formula, and discharge formula.<jupyter_code>x = predict_tools.generate_model_df('Li', 115, 19, 'P(WO4)2', 'LiP(WO4)2')<jupyter_output>/Users/andrewgonsalves/opt/miniconda3/lib/python3.7/site-packages/pandas/core/indexing.py:1418: FutureWarning: 
Passing list-likes to .loc or [] with any missing label will raise
KeyError in the future, you can use .reindex() as an alternative.

See the documentation here:
https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike
  return self._getitem_tuple(key)<jupyter_text>Then convert their value into a PyTorch ``Tensor``:<jupyter_code>x_torch = torch.tensor(x, dtype = torch.float)<jupyter_output><empty_output><jupyter_text>Now, calling the model on our data:<jupyter_code>y = model(x_torch)
y = model(x_torch).clone().detach()
y = np.array(y)
print(str(y[0]))<jupyter_output>[0.1821037  0.08646781]<jupyter_text>And that's it! To scale our data back:<jupyter_code>predict_tools.convert(y)<jupyter_output>[[469.98715 680.81177]]
{'fraction_non_alphanumeric': 0.07779646761984861, 'fraction_numerical': 0.016610597140454163, 'mean_word_length': 6.623397435897436, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '199605', 'license': 'MIT', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1382, 'n_words': 518, 'path': 'Examples/example_runthrough.ipynb', 'repo_name': 'kratos-batteries/kratos-batteries', 'size': '4756'}