CASMcode icon indicating copy to clipboard operation
CASMcode copied to clipboard

Fit ECIs manually

Open sjtuzhanglei opened this issue 1 year ago • 3 comments

Dear CASM developers,

In the case that I want to modify the total energy at 0 K from DFT by, say, adding vibrational contribution, or any other type of corrections, and then fit the ECIs, what would be the easiest way to do that?

Should I do it completely separately from casm-learn functionalities, or try to modify some of the key input files that casm-learn uses (the energy part specifically)?

Thanks!

sjtuzhanglei avatar Jan 05 '24 22:01 sjtuzhanglei

If you look at the casm learn --settings-format help for the "problem_specs"/"data" parameters, there are some options for specifying the input data. You could for instance add a new column to a "train" selection file and set "X": "new_column_name".

Alternatively, you can use any method you want to do the fitting and then use the Python function casm.project.write_eci to write the eci.json file.

bpuchala avatar Jan 09 '24 16:01 bpuchala

Hi Brian,

My train file is like this:

alias_or_name selected

SCEL1_1_1_1_0_0_0/0           1

SCEL1_1_1_1_0_0_0/1           1

SCEL1_1_1_1_0_0_0/2           1

SCEL1_1_1_1_0_0_0/3           1

SCEL1_1_1_1_0_0_0/4           1

SCEL1_1_1_1_0_0_0/5           1

SCEL1_1_1_1_0_0_0/6           1

SCEL1_1_1_1_0_0_0/7           1

......

Do you mean adding a third column to this "train" file with the column name "formation_free_energy", and setting the y value as "formation_free_energy" in the fit.json file?

Do I need to change "filetype" to csv or json and query the "corr" and "formation_free_energy" to an output csv or json file and let casm-learn read that output file?

If I am correct, casm-learn will somehow identify the "train" selection file, and read the X and y data from somewhere (where?) if X and y is not present in the "train" file?

Thanks!

{

"problem_specs": {

"data": {

  "filename": "train",

  "filetype": "selection",

  "X": "corr",

  "y": "formation_energy",

  "kwargs": null

},

On Tue, Jan 9, 2024 at 11:47 AM Brian Puchala @.***> wrote:

If you look at the casm learn --settings-format help for the "problem_specs"/"data" parameters, there are some options for specifying the input data. You could for instance add a new column to a "train" selection file and set "X": "new_column_name".

Alternatively, you can use any method you want to do the fitting and then use the Python function casm.project.write_eci https://github.com/prisms-center/CASMpython/blob/7cb55a10cfecf66e3fae1895aa9d1d2f9feb794c/casm/casm/project/io.py#L11C5-L11C14 to write the eci.json file.

— Reply to this email directly, view it on GitHub https://github.com/prisms-center/CASMcode/issues/345#issuecomment-1883409966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDNA5JTXRH5YWXZR6NIRKTYNVYBVAVCNFSM6AAAAABBPBPH4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBTGQYDSOJWGY . You are receiving this because you authored the thread.Message ID: @.***>

-- Lei Zhang Postdoc Scholar Mechanical Engineering Carnegie Mellon University Google Scholar https://scholar.google.com/citations?hl=en&view_op=list_works&gmla=AJsN-F51HKnfWWVxbsFk4uAWX43G9CzcwBr_848Z2BxrFiXa0q6bPGZqhzAADPpA0vojEKOVP8bkTFTV3wDI8XvJfy5V2hvIuRNadTccjO0J3niAX63sVSA&user=139-zKwAAAAJ Linkedin https://www.linkedin.com/in/lei-zhang-0b8aa126/

sjtuzhanglei avatar Jan 13 '24 20:01 sjtuzhanglei

Hi Brian,

I did what you said, but I got an error. Could you please help me on this?

{ "problem_specs": { "data": { "filename": "train.1.final_form_energy_sorted", "filetype": "selection", "X": "corr", "y": "final_formation_energy", "kwargs": null }, ......

# alias_or_name selected final_formation_energy SCEL1_1_1_1_0_0_0/0 1 0.0924656 SCEL1_1_1_1_0_0_0/1 1 0.1171833 SCEL1_1_1_1_0_0_0/2 1 0 SCEL1_1_1_1_0_0_0/3 1 -0.0417767 SCEL1_1_1_1_0_0_0/4 1 -0.0465267 SCEL1_1_1_1_0_0_0/5 1 -0.2006344 SCEL1_1_1_1_0_0_0/6 1 -0.0000511 SCEL1_1_1_1_0_0_0/7 0 ......

Loading fit_1_ga.json

Hall of Fame size: 10

Get problem data...

Traceback (most recent call last): File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3790, in get_loc return self._engine.get_loc(casted_key) File "index.pyx", line 152, in pandas._libs.index.IndexEngine.get_loc File "index.pyx", line 181, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'selected'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/global/homes/v/voz5005/.local/conda/envs/casm/bin/casm-learn", line 8, in sys.exit(main()) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/scripts/casm_learn.py", line 212, in main casm.learn.fit_and_select(input, File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/learn/feature_selection.py", line 58, in fit_and_select fdata = make_fitting_data(input, File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/learn/fit.py", line 1589, in make_fitting_data tdata = TrainingData(input, verbose=verbose) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/learn/fit.py", line 1401, in init columns = [ File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/learn/fit.py", line 1403, in if x not in sel.data.columns File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/project/selection.py", line 117, in data self._clean_data() File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/project/selection.py", line 232, in _clean_data self.astype('selected', bool) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/casm/project/selection.py", line 228, in astype columnname] = self._data.loc[:, File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexing.py", line 1147, in getitem return self._getitem_tuple(key) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexing.py", line 1330, in _getitem_tuple return self._getitem_lowerdim(tup) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexing.py", line 1039, in _getitem_lowerdim section = self._getitem_axis(key, axis=i) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexing.py", line 1393, in _getitem_axis return self._get_label(key, axis=axis) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexing.py", line 1343, in _get_label return self.obj.xs(label, axis=axis) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/generic.py", line 4222, in xs return self[key] File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/frame.py", line 3893, in getitem indexer = self.columns.get_loc(key) File "/global/homes/v/voz5005/.local/conda/envs/casm/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3797, in get_loc raise KeyError(key) from err KeyError: 'selected'

sjtuzhanglei avatar Aug 01 '24 21:08 sjtuzhanglei