spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
118 stars 52 forks source link

Getting Starting with Python #604

Open Ahsanu8 opened 2 years ago

Ahsanu8 commented 2 years ago

Hi,

I am a new user here. Is it possible to have a simple example of how I can start with python and get the output using cluster?

I tried to run the code e.g.

def evaluate(p_state): from spirit import system, quantities M = quantities.get_magnetization(p_state) E = system.get_energy(p_state) return M, E

But don't know how to get output and spin texture etc. Also, what is p_state here?

GPMueller commented 2 years ago

You can look at the scripts in the ui-python folder, for example this very basic LLG simulation script https://github.com/spirit-code/spirit/blob/master/ui-python/llg.py Please read up on how to use the input file (docs here) and in case that does not cover the specific case you are trying to realize, please feel free to ask more detailed questions.

Also, please don't use quantities.get_magnetization, as it is quite unreliable. It's better to take the array spin orientations (unit vectors) using system.get_spin_directions and calculate it yourself.

The output can be configured through the input file or corresponding settings in the Python-API or you can write your own output files. p_state is just a pointer to your calculation state, which you initialize with state.State (see the ui-python examples).

sfragkos commented 2 years ago

Hello everyone.

I am also a new user. I tried to build Spirit on Linux by using cmake but it didn't work out.

Therefore I desided to install it with "pip install spirit" and run it with python script.

The problem now is that I don't know how to run a calculation. Which is the executable? What should my input file be and how should I name it?

I really sorry but I'm a bit confused.

Best regards!

GPMueller commented 2 years ago

Beginner tutorials are unfortunately still an open issue (see #542).

@sfragkos could you please document what exactly didn't work?

Note that installing the Python package gives you access to a Python module, not a GUI executable. There is a default input-file in the "input" folder. Regarding what to do in Python, please take a look at the links I provided above and let us know if something specific is still unclear.

You may also find the discussions in the related issues #573 and #571 helpful.

sfragkos commented 2 years ago

Dear Mueller,

Thank very much for answering!

I finally made it. I installed it and it's very user friendly.

Best regards.

Ahsanu8 commented 2 years ago

Hi, I have seen the updated list of Questions in Provide a Tutorial #542.

Can you also add the following questions which I have,

Why do we need an input file? Is the input file is different from the script file? When we make an input file we must mention it in the script file? e.g.

from spirit import state, simulation with state.State("input/input.cfg") as p_state: simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB)

Thanks

Ahsanu8 commented 2 years ago

Also, I am not sure where I can look for output, etc if I am using python. What is a logfile? How to read it for output?

GPMueller commented 2 years ago

Why do we need an input file?

The input file provides a few features that are not available through the Python-API or the GUI, such as the configuration of your lattice's basis-cell. Otherwise you can choose what to use depending on your use-case and what seems more convenient to you.

I am not sure where I can look for output, etc if I am using python.

Regarding Python-questions please make sure to read the documentation and see if that clears up your questions. In this case, you'll find the relevant API here: https://spirit-docs.readthedocs.io/en/latest/core/docs/python-api/parameters.html#spirit.parameters.llg.set_output_configuration

What is a logfile? How to read it for output?

I don't understand your question. If you open one of the log files it should be clear what their purpose is. See also the corresponding docs for the config file and the PythonAPI