Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCSXML file #38

Open
nim-hrkn opened this issue Feb 3, 2023 · 3 comments
Open

FCSXML file #38

nim-hrkn opened this issue Feb 3, 2023 · 3 comments

Comments

@nim-hrkn
Copy link

nim-hrkn commented Feb 3, 2023

The preparation stage of AiiDA CalcJob does not allow direct use of file paths, which makes it difficult to create AiiDA scripts using ALM.
Python code is

            reg = LinearRegression(fit_intercept=False).fit(X, y)
            alm.set_fc(reg.coef_)
            alm.save_fc(filename=fname_fcs, format="alamode")

and fname_fcs is used in anphon input as

 FCSXML = {fname_fcs}

But, AiiDA can't specify fname_fcs as far as I understand. AiiDA script must be something like

 with folder.open(self.options.input_filename, 'w', encoding='utf8') as handle:
            make_alm_in(alm_param, handle=handle)

Is it possible to use the file hander instead of fname_fcs?

Probably
fc2 = alm.get_fc(1, mode='all')
can obtain all the harmonic force costants.

Though https://alm.readthedocs.io/en/develop/python-module.html?highlight=create_dataset intoduces

    with h5py.File('fc.hdf5', 'w') as w:
        w.create_dataset('fc2', data=fc2, compression='gzip')
        w.create_dataset('fc3', data=fc3, compression='gzip')

how can I make the FCSXML file from fc2?

@ttadano
Copy link
Owner

ttadano commented Feb 3, 2023

The force constant writer in the FCSXML format is implemented as a C++ function, and the python method alm.save_fc is a simple wrapper to that function. I think it is not easy to use the C++ function in a way as with open() as f.

I implemented another class 'Fcsxml' (still in the alpha stage), which can write force constants in the FCSXML format. Could you have a look at https://github.com/ttadano/ALM/blob/develop/python/alm/fcsxml.py?

While this class still does not have a method like write(self, fileobj=f), implementing it would be straightforward.

@nim-hrkn
Copy link
Author

nim-hrkn commented Feb 3, 2023

Thank you for you quick reply.
Probably the usage is like this using ase,Atoms class.

lavec = atoms.cell
xcoord = atoms.get_scaled_potisions
numbers = atoms.numbers
fcsxml = Fcsxml(lavec, xcoord, numbers)
...
fc2 = alm.get_fc(1, mode='all')
fcsxml,set_force_constants(fc2, fc_indices)
fcsxml.write(filename)

fc_indices is explained as

        fc_indices: array_like, dtype='int', shape=(num_fc, fc_order + 1)
            Array of flattened indices 3 * index_atom + index_xyz of the
            force constants.

But I can't understand it. Could I ask you how to specify fc_indeces ?

@ttadano
Copy link
Owner

ttadano commented Feb 3, 2023

The get_fc method of alm returns the force constant values and element indices, and they can be passed to fcsxml.set_force_constants as

fc2_values, fc2_elems = alm.get_fc(1)
fcsxml.set_force_constants(fc2_values, fc2_elems)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants