<jupyter_start><jupyter_text>Load Ni-Mo data<jupyter_code>from pymatgen.core import Structure
from monty.serialization import loadfn

data = loadfn('data.json')
train_structures = [d['structure'] for d in data]
train_energies = [d['outputs']['energy'] for d in data]
train_forces = [d['outputs']['forces'] for d in data]<jupyter_output><empty_output><jupyter_text>Setup the initial weights for training (If not, the weights for energy and force will be both equal to 1)<jupyter_code>import numpy as np
from maml.utils import pool_from, convert_docs

train_pool = pool_from(train_structures, train_energies, train_forces)
_, df = convert_docs(train_pool)

weights = np.ones(len(df['dtype']), )

# set the weights for energy equal to 100
weights[df['dtype'] == 'energy'] = 100<jupyter_output><empty_output><jupyter_text>Set up the qSNAP and train<jupyter_code>from maml.base import SKLModel
from maml.describers import BispectrumCoefficients
from sklearn.linear_model import LinearRegression
from maml.apps.pes import SNAPotential

element_profile = {'Mo': {'r': 5.0, 'w': 1}, 'Ni': {'r': 5.0, 'w': 1}}
describer = BispectrumCoefficients(rcutfac=0.5, twojmax=6, element_profile=element_profile, 
                                   quadratic=True, pot_fit=True)
model = ModelWithSklearn(describer=describer, model=LinearRegression())
qsnap = SNAPotential(model=model)
qsnap.train(train_structures, train_energies, train_forces, sample_weight=weights)<jupyter_output><empty_output><jupyter_text>Predict the energies, forces of training data<jupyter_code>df_orig, df_predict = qsnap.evaluate(test_structures=train_structures, 
                                     test_energies=train_energies,
                                     test_forces=train_forces, test_stresses=None)
df_predict[df_predict['dtype'] == 'energy']<jupyter_output><empty_output><jupyter_text>Lattice constant, Elastic constant Large error due to limited training data -- 10 structures<jupyter_code>from pymatgen.core import Lattice

Ni = Structure.from_spacegroup(sg='Fm-3m', species=['Ni'], lattice=Lattice.cubic(3.51), coords=[[0, 0, 0]])
Mo = Structure.from_spacegroup(sg='Im-3m', species=['Mo'], lattice=Lattice.cubic(3.17), coords=[[0, 0, 0]])
from maml.apps.pes import ElasticConstant

Ni_ec_calculator = ElasticConstant(ff_settings=qsnap)
Ni_C11, Ni_C12, Ni_C44, _ = Ni_ec_calculator.calculate([Ni])[0]
print('Ni', ' C11: ', Ni_C11, 'C12: ', Ni_C12, 'C44: ', Ni_C44)
Mo_ec_calculator = ElasticConstant(ff_settings=qsnap)
Mo_C11, Mo_C12, Mo_C44, _ = Mo_ec_calculator.calculate([Mo])[0]
print('Mo', ' C11: ', Mo_C11, 'C12: ', Mo_C12, 'C44: ', Mo_C44)<jupyter_output>Mo  C11:  -339.481069999747 C12:  -281.969206500333 C44:  287304.423364424<jupyter_text>Load from parameters files<jupyter_code>qsnap_loaded = SNAPotential.from_config(param_file='SNAPotential.snapparam', coeff_file='SNAPotential.snapcoeff')<jupyter_output><empty_output><jupyter_text>Energy, force, stress prediction<jupyter_code>from maml.apps.pes import EnergyForceStress

efs_calculator = EnergyForceStress(ff_settings=qsnap_loaded)
energy, forces, stresses = efs_calculator.calculate([train_structures[0]])[0]

print('energy: {}'.format(energy))
print('forces: \n', forces)
print('stresses: ', stresses)<jupyter_output>energy: -1022.38144474744
forces: 
 [[-0.104955    0.602339    0.0869616 ]
 [ 0.566629   -0.416801   -0.767495  ]
 [-0.431159   -0.0925376   0.529552  ]
 [ 0.195108    0.356172   -0.401171  ]
 [-0.609619   -0.0679634  -1.50584   ]
 [ 0.438837    0.0907875  -0.254665  ]
 [-0.697364    0.154224    0.264859  ]
 [-0.141106    0.0327338   0.764932  ]
 [-1.22901    -0.512032    0.242512  ]
 [ 0.684857   -0.33278    -0.464771  ]
 [ 0.0443069  -0.12094     0.0441682 ]
 [-0.802489    0.0899697  -0.591699  ]
 [-0.0910656  -0.132209    0.617263  ]
 [-0.201382   -0.605774   -0.107575  ]
 [ 0.293304   -0.775934   -1.30117   ]
 [-0.628046   -0.540387    0.219001  ]
 [-0.210253   -0.151532   -0.116492  ]
 [-0.223493   -0.0582363  -0.540316  ]
 [-0.0291229  -0.336132    1.15714   ]
 [-0.375756    0.204714   -0.446726  ]
 [-0.715109    0.598777    0.427773  ]
 [-0.224202   -0.00220803  0.0843487 ]
 [-0.240748    1.51498     0.823912  ]
 [ 0.943472   -0.347317   -0.281062  ]
 [-0.0558738  -0.540331    0[...]
{'fraction_non_alphanumeric': 0.13873916100304665, 'fraction_numerical': 0.15584719943754394, 'mean_word_length': 4.154589371980676, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '133951', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1686, 'n_words': 301, 'path': 'notebooks/pes/qsnap/example.ipynb', 'repo_name': 'sgbaird/maml', 'size': '4267'}