spirit-code / spirit

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

Get quantities : e.g. magnetization #574

Closed Abdou137 closed 4 years ago

Abdou137 commented 4 years ago

Dear all, I want to extract the magnetisation from a simulation, it gives the following error :

spirit.quantities.get_magnetization(p_state, idx_image=-1, idx_chain=-1) NameError: name 'spirit' is not defined


The code I used was simple :

import os
import sys

### Make sure to find the Spirit modules
### This is only needed if you did not install the package
spirit_py_dir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), "../core/python"))
sys.path.insert(0, spirit_py_dir)

#from spirit import state
from spirit import io
from spirit import simulation
from spirit import configuration
from spirit import state

# Import Spirit modules
spirit_py_dir = os.path.abspath(os.path.join(
    os.path.dirname(__file__), "../core/python"))
sys.path.insert(0,spirit_py_dir ) 

with state.State("input/CrIiii_HC.cfg") as p_state:
    simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB)
    spirit.quantities.get_magnetization(p_state, idx_image=-1, idx_chain=-1)

I didn't find where is the problem . thus I will appreciate any kind of help with nice regards

GPMueller commented 4 years ago

This has nothing to do with Spirit. Please familiarize yourself with the way Python imports work (as the error already tells you, you cannot use something you neither defined nor imported). My tip: look at the usage of the simulation submodule and use the quantities submodule in the same way.

Abdou137 commented 4 years ago

Dear Mr. MUELLER, Thank you very much , I fixed it I think.

I will appreciate any kind of help with nice regards

GPMueller commented 4 years ago

Maybe you found these things on your own already, but in case not:

  1. it depends on how you'd like to do it. You can of course read the orientations from the ovf file, or you could use the system.get_spin_directions API method: https://spirit-docs.readthedocs.io/en/latest/core/docs/python-api/spirit.system.html#spirit.system.get_spin_directions - calculating the magnetization values from these arrays is of course trivial
  2. you can look at ui-python/mc.py for some inspiration, but the way you describe calculating the hysteresis is conceptually ok
  3. there is no ui-python/main.py on the develop branch. If you want to run that older file, you need to update the function names to the ones given in the documentation
  4. See the documentation on the input parameters for the available output files. Any other output you wish to have you can simply write yourself - it is very easy to do in Python