Closed Wblogger closed 2 years ago
In your python snippet it seems like you tried to use the ovf file as an input. Here is a minimal example of how to print out the topological charge, assuming an input "input.cfg" and an ovf file "abc.ovf"
from spirit import state, quantities, io, system
INPUT_FILE = "input.cfg"
IMAGE_FILE = "abc.ovf"
with state.State(INPUT_FILE) as p_state:
io.image_read(p_state, IMAGE_FILE)
topological_charge = quantities.get_topological_charge(p_state)
print(f"top. charge = {topological_charge}\n")
@MSallermann Thanks a lot for your help! But after I tried it, it showed INPUT_FILE = "input.cfg" ^ IndentationError: unexpected indent
Anyway, very grateful
@Wblogger that has nothing to do with the snippet that @MSallermann provided to you and should be obvious how to fix.
I'm happy you're trying to use Spirit, but I would suggest that you familiarize yourself a little more with Python, or I'm afraid you'll be likely to run into many more problems with the Python API of Spirit
I found a way to get the topological charge number. Used as follows:
from spirit import simulation, state, quantities, configuration, system, io
with state.State("input/input.cfg") as p_state:
configuration.plus_z(p_state)
io.image_read(p_state,"1.ovf")
simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_RK4)
F = quantities.get_topological_charge(p_state)
M = quantities.get_magnetization(p_state)
E = system.get_energy(p_state)
print (F)
print (M)
print (E)
topological_charge=str(F)
magnetization=str(M)
total_Energy=str(E)
with open('/home/result.txt','w') as file_handle:
# file_handle.truncate(0)
file_handle.write("topological_charge:")
file_handle.write('\n')
file_handle.write(topological_charge)
file_handle.write('\n')
file_handle.write("magnetization:")
file_handle.write('\n')
file_handle.write(magnetization)
file_handle.write('\n')
file_handle.write("total_Energy:")
file_handle.write('\n')
file_handle.write(total_Energy)
file_handle.write('\n')
#with open('test.txt','a') as file_handle:
I have a lot to learn in python. Thank you very much for your valuable suggestions. @MSallermann @GPMueller
Dear Spirit users and developers,
I'm new on Spirit and I have a question on reading an existing ovf file with python.
Previously, I used to run spirit in a windowed interface under Ubuntu.I created a single hexagonal lattice in the input file and ran it to generate the corresponding ovf file. However, I can't get the data about the topological charge. Do I need to run the ovf file again with python to get the topological charge data? If so, how would the code be written? (Assuming the ovf file name is abc.ovf) or is there another way to get the topological charge data? I tried to run a single hexagonal lattice ovf file with only one skyrmion in python, and it shows that the topological charge is 35, while the real topological charge number should be 1.
The python code written is as follows.
I would be very grateful for any help!