ModuleNotFoundError: No module named ‘aiida_quantumespresso.calculations.functions.create_magnetic_configuration’

Hi,
I am trying to repeat the magnetic calculation with aiida_quantumespreeso.
https://aiida-quantumespresso.readthedocs.io/en/latest/tutorials/magnetism.html

The program failed at this step:

from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration

results = create_magnetic_configuration(structure, [-2, 2])

It says

ModuleNotFoundError: No module named ‘aiida_quantumespresso.calculations.functions.create_magnetic_configuration’

Also if I type the sentences, the modules can not be auto detected by pressing ‘tab’. It can just automatically find something like "aiida_quantumespresso.calculations.functions.create_kpoints_from_distance "

Did I miss anything when installing the software package?

The total jupyterpy record is here

+*In[1]:*+
[source, ipython3]
----
from aiida import orm, load_profile

load_profile()
----


+*Out[1]:*+
----Profile<uuid='c633e7bf80b9436ba2a73f137476acfe' name='quicksetup'>----


+*In[4]:*+
[source, ipython3]
----
from ase.build import bulk

structure = orm.StructureData(ase=bulk('Co', 'hcp', 2.5, 4.06))
#pw_code = orm.load_code('qe-7.2-pw@localhost')
pw_code = orm.load_code('pw@localhost')
----


+*In[12]:*+
[source, ipython3]
----
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain

builder = PwBaseWorkChain.get_builder_from_protocol(
    structure=structure,
    code=pw_code,
    protocol='fast' 
#    pseudo_family = load_group('SSSP/1.3/PBE/efficiency')
  #  pseudo_family =  'SSSP/1.3/PBE/efficiency' 
)
----


+*In[13]:*+
[source, ipython3]
----
parameters = builder.pw.parameters.get_dict()
parameters['SYSTEM']['nspin'] = 2
parameters['SYSTEM']['starting_magnetization'] = {'Co': 1}
builder.pw.parameters = orm.Dict(parameters)
----


+*In[14]:*+
[source, ipython3]
----
from aiida.engine import run_get_node

results, pwbase_node = run_get_node(builder)
----


+*Out[14]:*+
----
02/04/2024 11:09:35 AM <118424> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [362|PwBaseWorkChain|run_process]: launching PwCalculation<367> iteration #1
02/04/2024 11:10:03 AM <118424> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [362|PwBaseWorkChain|results]: work chain completed after 1 iterations
02/04/2024 11:10:03 AM <118424> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [362|PwBaseWorkChain|on_terminated]: remote folders will not be cleaned
----


+*In[15]:*+
[source, ipython3]
----
results['output_parameters'].get_dict()['total_magnetization']
----


+*Out[15]:*+
----3.36----


+*In[17]:*+
[source, ipython3]
----
#Using the SpinType
from aiida_quantumespresso.common.types import SpinType

builder = PwBaseWorkChain.get_builder_from_protocol(
    structure=structure,
    code=pw_code,
    protocol='fast',
    spin_type=SpinType.COLLINEAR
)
----


+*In[18]:*+
[source, ipython3]
----
builder.pw.parameters.get_dict()['SYSTEM']['starting_magnetization']
----


+*Out[18]:*+
----{'Co': 0.29411764705882354}----


+*In[19]:*+
[source, ipython3]
----
results, pwbase_node = run_get_node(builder)
----


+*Out[19]:*+
----
02/12/2024 10:00:32 AM <118424> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [378|PwBaseWorkChain|run_process]: launching PwCalculation<383> iteration #1
02/12/2024 10:00:56 AM <118424> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [378|PwBaseWorkChain|results]: work chain completed after 1 iterations
02/12/2024 10:00:56 AM <118424> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [378|PwBaseWorkChain|on_terminated]: remote folders will not be cleaned
----


+*In[20]:*+
[source, ipython3]
----
results['output_parameters'].get_dict()['total_magnetization']
----


+*Out[20]:*+
----3.36----


+*In[21]:*+
[source, ipython3]
----
structure.sites
----


+*Out[21]:*+
----[<Site: kind name 'Co' @ 0.0,0.0,0.0>,
 <Site: kind name 'Co' @ -2.7755575615629e-17,1.4433756729741,2.03>]----


+*In[26]:*+
[source, ipython3]
----
#from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration
from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration 
#from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration   
results = create_magnetic_configuration(structure, [-2, 2])
----


+*Out[26]:*+
----

    ---------------------------------------------------------------------------

    ModuleNotFoundError                       Traceback (most recent call last)

    Cell In[26], line 2
          1 #from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration
    ----> 2 from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration 
          3 #from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration   
          4 results = create_magnetic_configuration(structure, [-2, 2])


    ModuleNotFoundError: No module named 'aiida_quantumespresso.calculations.functions.create_magnetic_configuration'

----


+*In[27]:*+
[source, ipython3]
----
from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration

results = create_magnetic_configuration(structure, [-2, 2])
----


+*Out[27]:*+
----

    ---------------------------------------------------------------------------

    ModuleNotFoundError                       Traceback (most recent call last)

    Cell In[27], line 1
    ----> 1 from aiida_quantumespresso.calculations.functions.create_magnetic_configuration import create_magnetic_configuration
          3 results = create_magnetic_configuration(structure, [-2, 2])


    ModuleNotFoundError: No module named 'aiida_quantumespresso.calculations.functions.create_magnetic_configuration'

----


+*In[ ]:*+
[source, ipython3]
----

----


+*In[ ]:*+
[source, ipython3]
----

----

Many thanks for that.

Sincerely,
Dr. Guoyu Yang
Lecturer
Jimei Univ, School of Science, Digital Fujian Big Data Modeling and Intelligent Computing Institute
185 Yinjiang Rd.,
Jimei District, Xiamen,361021
Fujian, China
E-mail: 201961000100@jmu.edu.cn

Hi @AmberLEE123456,
which version of the AiiDA-QE plugin are you using? You can check it via

pip show aiida-quantumespresso
(aiida_QE) yang@yang-Inspiron-3670:~/AiiDA/tutorial_ssh/01_a0s000508$ pip show aiida-quantumespresso
Name: aiida-quantumespresso
Version: 4.3.0
Summary: The official AiiDA plugin for Quantum ESPRESSO
Home-page: 
Author: 
Author-email: The AiiDA team <developers@aiida.net>
License: 
Location: /home/yang/miniforge3/envs/aiida_QE/lib/python3.11/site-packages
Requires: aiida-pseudo, aiida_core, click, importlib_resources, jsonschema, numpy, packaging, pydantic, qe-tools, xmlschema
Required-by: 
(aiida_QE) yang@yang-Inspiron-3670:~/AiiDA/tutorial_ssh/01_a0s000508$

Sincerely,
Dr. Guoyu Yang
Lecturer
Jimei Univ, School of Science, Digital Fujian Big Data Modeling and Intelligent Computing Institute
185 Yinjiang Rd.,
Jimei District, Xiamen,361021
Fujian, China
E-mail: 201961000100@jmu.edu.cn

The feature was added in version 4.4: aiida-quantumespresso/CHANGELOG.md at main · aiidateam/aiida-quantumespresso · GitHub

So upgrading the AiiDA-QE plugin to at least v 4.4 should solve the problem.

Hope that helps,
Timo

1 Like