atomistic-machine-learning / schnetpack

SchNetPack - Deep Neural Networks for Atomistic Systems
Other
792 stars 215 forks source link

AttributeError: 'float' object has no attribute 'copy' #555

Closed xiehuanyi closed 1 year ago

xiehuanyi commented 1 year ago

I followed the tutoration here https://schnetpack.readthedocs.io/en/stable/tutorials/tutorial_01_preparing_data.html and my code are like this

from schnetpack.data import ASEAtomsData
from ase import Atoms
import numpy as np

# load atoms from npz file. Here, we only parse the first 10 molecules
data = np.load('data.npy', allow_pickle=True)
print(data[0].keys())

atoms_list = []
property_list = []

for d in data:
    ats = Atoms(positions=d['coordinates'], numbers=d['elements'])
    properties = {'energy': d['energy'],
                 'forces': d['force']}
    atoms_list.append(ats)
    property_list.append(properties)

print(atoms_list[-1])
print(property_list[-1])

new_dataset = ASEAtomsData.create(
    './ali.db',
    distance_unit='Ang',
    property_unit_dict={'energy':'kcal/mol', 'forces':'kcal/mol/Ang'}
)
new_dataset.add_systems(property_list, atoms_list)

but when I tried to load it, I got this error, my code is here

data = load_dataset('data/ali.db', format=AtomsDataFormat.ASE)
for i in data:
    print(i)
    break
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_53/3542366375.py in <module>
      1 data = load_dataset('data/ali.db', format=AtomsDataFormat.ASE)
----> 2 for i in data:
      3     print(i)
      4     break

/opt/conda/lib/python3.8/site-packages/schnetpack/data/atoms.py in __getitem__(self, idx)
    267             idx = self.subset_idx[idx]
    268 
--> 269         props = self._get_properties(
    270             self.conn, idx, self.load_properties, self.load_structure
    271         )

/opt/conda/lib/python3.8/site-packages/schnetpack/data/atoms.py in _get_properties(self, conn, idx, load_properties, load_structure)
    345         for pname in load_properties:
    346             properties[pname] = (
--> 347                 torch.tensor(row.data[pname].copy()) * self.conversions[pname]
    348             )
    349 

AttributeError: 'float' object has no attribute 'copy'

and my packages versions are shown below

Package                       Version
----------------------------- -----------
aiohttp                       3.8.5
aiosignal                     1.3.1
alabaster                     0.7.12
alembic                       1.8.0
antlr4-python3-runtime        4.9.3
anyio                         3.6.1
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
ase                           3.22.1
async-timeout                 4.0.2
attrs                         21.4.0
autopage                      0.5.1
autopep8                      1.6.0
Babel                         2.10.3
backcall                      0.2.0
beautifulsoup4                4.10.0
bleach                        5.0.1
brotlipy                      0.7.0
certifi                       2021.10.8
cffi                          1.15.0
chardet                       4.0.0
charset-normalizer            2.0.4
click                         8.1.3
cliff                         3.10.1
cmaes                         0.8.2
cmd2                          2.4.1
colorama                      0.4.5
colorlog                      6.6.0
conda                         4.11.0
conda-build                   3.21.7
conda-content-trust           0+unknown
conda-package-handling        1.7.3
cryptography                  36.0.0
cycler                        0.11.0
debugpy                       1.6.2
decorator                     5.1.1
defusedxml                    0.7.1
dgl-cu113                     0.8.2.post1
dglgo                         0.0.1
dirsync                       2.2.5
dnspython                     2.2.1
docutils                      0.18.1
easydict                      1.9
entrypoints                   0.4
fasteners                     0.18
fastjsonschema                2.16.1
filelock                      3.4.2
fonttools                     4.34.4
frozenlist                    1.4.0
fsspec                        2023.6.0
glob2                         0.7
greenlet                      1.1.2
h5py                          3.9.0
hydra-colorlog                1.2.0
hydra-core                    1.3.2
idna                          3.3
imagesize                     1.4.1
importlib-metadata            4.12.0
importlib-resources           5.8.0
ipykernel                     6.15.1
ipython                       7.31.1
ipython-genutils              0.2.0
isort                         5.10.1
jedi                          0.18.1
Jinja2                        3.1.2
joblib                        1.1.0
json5                         0.9.8
jsonschema                    4.7.2
jupyter-client                7.3.4
jupyter-core                  4.11.1
jupyter-server                1.18.1
jupyterlab                    3.0.0
jupyterlab-pygments           0.2.2
jupyterlab-server             2.15.0
kiwisolver                    1.4.4
libarchive-c                  2.9
lightning-utilities           0.9.0
littleutils                   0.2.2
Mako                          1.2.1
markdown-it-py                3.0.0
MarkupSafe                    2.0.1
matplotlib                    3.5.2
matplotlib-inline             0.1.2
matscipy                      0.8.0
mdurl                         0.1.2
mistune                       0.8.4
mkl-fft                       1.3.1
mkl-random                    1.2.2
mkl-service                   2.4.0
mpmath                        1.3.0
multidict                     6.0.4
nbclassic                     1.0.0
nbclient                      0.6.6
nbconvert                     6.5.0
nbformat                      5.4.0
nest-asyncio                  1.5.5
networkx                      2.8.4
notebook_shim                 0.2.3
numpy                         1.21.2
numpydoc                      1.4.0
ogb                           1.3.3
omegaconf                     2.3.0
optuna                        2.10.1
outdated                      0.2.1
packaging                     21.3
pandas                        1.4.3
pandocfilters                 1.5.0
parso                         0.8.3
pbr                           5.9.0
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        9.0.1
pip                           21.2.4
pkginfo                       1.8.2
prettytable                   3.3.0
prometheus-client             0.14.1
prompt-toolkit                3.0.20
psutil                        5.8.0
ptyprocess                    0.7.0
pycodestyle                   2.8.0
pycosat                       0.6.3
pycparser                     2.21
pydantic                      1.9.1
Pygments                      2.15.1
pyOpenSSL                     21.0.0
pyparsing                     3.0.9
pyperclip                     1.8.2
pyrsistent                    0.18.1
PySocks                       1.7.1
python-dateutil               2.8.2
python-etcd                   0.4.5
pytorch-lightning             2.0.6
pytz                          2021.3
PyYAML                        6.0
pyzmq                         23.2.0
requests                      2.27.1
rich                          13.5.2
ruamel.yaml                   0.17.21
ruamel.yaml.clib              0.2.6
ruamel-yaml-conda             0.15.100
schnetpack                    2.0.3
scikit-learn                  1.1.1
scipy                         1.8.1
Send2Trash                    1.8.0
setuptools                    58.0.4
six                           1.16.0
sniffio                       1.2.0
snowballstemmer               2.2.0
soupsieve                     2.3.1
Sphinx                        5.0.2
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.5
SQLAlchemy                    1.4.39
stevedore                     3.5.0
sympy                         1.12
terminado                     0.15.0
threadpoolctl                 3.1.0
tinycss2                      1.1.1
toml                          0.10.2
torch                         1.11.0
torch-cluster                 1.6.0
torch-ema                     0.3
torch-geometric               2.0.4
torch-scatter                 2.0.9
torch-sparse                  0.6.14
torch-spline-conv             1.2.1
torchelastic                  0.2.2
torchmetrics                  1.0.2
torchtext                     0.12.0
torchvision                   0.12.0
tornado                       6.2
tqdm                          4.62.3
traitlets                     5.3.0
typer                         0.4.2
typing_extensions             4.7.1
urllib3                       1.26.7
wcwidth                       0.2.5
webencodings                  0.5.1
websocket-client              1.3.3
wheel                         0.37.1
yarl                          1.9.2
zipp                          3.8.0
stefaanhessmann commented 1 year ago

Hi @xiehuanyi the physical properties in the database need to be stored as np.array instead of floats. Propably changing this 'energy': d['energy'] to 'energy': np.array([d['energy']) should solve your problem. Let me know if this helps. Best Stefaan