3
$\begingroup$

I am trying to run a Python script using ASE library, I have installed ASE using this page and run my Python script using this library on my terminal. I have made a virtual env named 'MLC_env' and have already installed the ASE library there.

Python script

from ase import Atoms
atoms = Atoms('N2')
print(atoms.positions)

Error: While trying to run the above python script

(MLC_env) (base) anshumansinha@Anshumans-MacBook-Pro-3 Q1 % python3 struct.py
Traceback (most recent call last):
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/py3k.py", line 24, in <module>
    import pickle5 as pickle
  File "/Users/anshumansinha/.local/lib/python3.10/site-packages/pickle5/__init__.py", line 1, in <module>
    from .pickle import *
  File "/Users/anshumansinha/.local/lib/python3.10/site-packages/pickle5/pickle.py", line 33, in <module>
    from struct import pack, unpack
  File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
    from ase import Atoms
ImportError: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/overrides.py", line 8, in <module>
    from numpy.compat._inspect import getargspec
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/__init__.py", line 12, in <module>
    from . import py3k
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/py3k.py", line 26, in <module>
    import pickle
  File "/Users/anshumansinha/miniforge3/lib/python3.10/pickle.py", line 33, in <module>
    from struct import pack, unpack
  File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
    from ase import Atoms
ImportError: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
    from ase import Atoms
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py", line 17, in <module>
    from ase.atom import Atom
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/atom.py", line 3, in <module>
    import numpy as np
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/__init__.py", line 141, in <module>
    from . import core
  File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "/Users/anshumansinha/Desktop/MLC/MLC_env/bin/python3"
  * The NumPy version is: "1.24.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)
$\endgroup$
4
  • 2
    $\begingroup$ "from ase.atoms import Atoms" check whether this is working? $\endgroup$ Feb 2, 2023 at 4:47
  • 1
    $\begingroup$ Where you able to rectify the error OP? $\endgroup$ Feb 5, 2023 at 18:16
  • $\begingroup$ Close voters: if an on-topic question is not a duplicate, spam, or VLQ, and it has an answer with a positive score, we generally keep them open. The question is not taking up space in our unanswered queue, so we don't see significant harm in keeping the question open. $\endgroup$ Feb 19, 2023 at 21:20
  • $\begingroup$ OP, Did you try installing ASE using the steps mentioned below? Please update the status. $\endgroup$ Apr 3, 2023 at 18:34

1 Answer 1

6
$\begingroup$

There are few issues here:

You have been calling the constructor to the atom object wrong: If you refer to the ASE manual, and go to Atoms object section, you will see that you need to explicitly set the positions for the atoms in the molecule that you are creating. Consider the example of creating a carbon-monoxide molecule, you will do it as follows:

from ase import Atoms 
d = 1.1 
co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)])

The error message in your case is trying to say that you have not set the positions for the atoms, but is then trying to access that property (which the system does not have)

Editing the answer to address the comment by Cavenfish:

Following the link in the error message, it seems that the issue is with the installation of ase. I tried installing ase in a virtualenv using two methods

  1. Normal pip install --upgrade --user ase, and
  2. pip install --upgrade git+https://gitlab.com/ase/ase.git@master

In the first method, the installation completed, but had errors with the dependencies, particularly numpy. Using the second method, I was able to install and use ase without any issues.

Thus it seems that OP might have used the first method, and inadvertently had some issues with the dependencies.

$\endgroup$
2
  • $\begingroup$ You are correct that the Atoms call was not made properly but the error message has to to with the installation of ASE. If you run the sample code from the question it prints out [[0. 0. 0.],[0. 0. 0.]] as long as you have the correct ASE installation. $\endgroup$
    – Cavenfish
    Feb 2, 2023 at 16:28
  • 1
    $\begingroup$ It might be possible. The only way to know that is if OP can either (i) try reinstalling ASE in a different virtualenv, and see if the error persists or (ii) by testing the installation using unit tests available. My comment came from a C++ background, where the code will crib if you call the constructor wrong. $\endgroup$ Feb 2, 2023 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .