jkitchin / vasp

New ASE compliant Python interface to VASP
122 stars 58 forks source link

DB.db stumbling on 'charges' entry #17

Closed jboes closed 2 years ago

jboes commented 8 years ago

I've been struggling with the following error this afternoon:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/home-research/jboes/python/ase/ase/db/core.py", line 283, in get
    rows = list(self.select(selection, limit=2, **kwargs))
  File "/home-research/jboes/python/ase/ase/db/core.py", line 396, in select
    limit=limit, offset=offset, sort=sort):
  File "/home-research/jboes/python/ase/ase/db/sqlite.py", line 529, in _select
    yield self._convert_tuple_to_row(values)
  File "/home-research/jboes/python/ase/ase/db/sqlite.py", line 360, in _convert_tuple_to_row
    dct['charges'] = deblob(values[24])
  File "/home-research/jboes/python/ase/ase/db/sqlite.py", line 616, in deblob
    array = np.frombuffer(buf, dtype)
ValueError: buffer size must be a multiple of element size

I have tried this with and without my changes to the write_db function, and the error seems to be independent of the changes.

It only seems to occur with new calculations, and also only when the write_db function is called in some way. Here are the two code blocks I've been using to test this. If someone could verify so I can know if this is a personal change or not, I'd greatly appreciate it.

from vasp import Vasp
from ase.lattice.surface import fcc111
Vasp.VASPRC['queue.walltime'] = '24:00:00'

atoms = fcc111('Au', [1, 1, 7], a=3.934, vacuum=6.0)

calc = Vasp('vasp-DB-old',
        xc='pbe',
        kpts=[10, 10, 1],
        encut=250,
        nsw=0,
        atoms=atoms)
print(calc.potential_energy)

Run this after the top calculations is finished, which takes about 4 minutes.

from vasp import Vasp
from ase.db import connect

calc = Vasp('vasp-DB-old')
calc.write_db()

db = connect('vasp-DB-old/DB.db')
d = db.get()

data = d.data
data.update(d.key_value_pairs)

for k, v in data.iteritems():
    print k, v
jkitchin commented 8 years ago

I get this output:

+RESULTS:

:RESULTS: resort [0 1 2 3] version 0.9.2 parameters {u'kpts': array([1, 1, 1]), u'xc': u'pbe', u'pp': u'PBE', u'encut': 250, u'lcharg': False, u'ismear': 1, u'lwave': False, u'sigma': 0.1, u'nsw': 0} path /home-research/jkitchin/kitchin-python/vasp/tests/vasp-DB-old ppp_list [[u'Au', u'potpaw_PBE/Au/POTCAR', 4]] jobid 1420675.gilgamesh.cheme.cmu.edu :END:

The jobid shouldn't be there, but otherwise I get no error.

jboes commented 8 years ago

Which version of ASE are you using?

jkitchin commented 8 years ago

good question. Here is the top of my git log. It looks like the last change I have is from 2 months ago.

4c35912 * master origin/unicode origin/master origin/HEAD unicode merge conflict |\ 257edb7 | * Merge branch 'stur86/ase-quaternions-enhanced' | |\ 0a3b98a | | * Drop mult and pep8 stuff 6206db1 | | * Fix bad indentation

John


Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu

On Mon, Jul 11, 2016 at 6:38 PM, Jacob Boes notifications@github.com wrote:

Which version of ASE are you using?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jkitchin/vasp/issues/17#issuecomment-231886845, or mute the thread https://github.com/notifications/unsubscribe/ABiRVgbTM6I4qtpx1PUeZSuadGkmMIiEks5qUsXegaJpZM4JJoLK .

jboes commented 8 years ago

This is frustrating. All versions of ASE > 3.9 seem to produce this error for me, even your checkout. I've not implemented any of my own changes into ASE or vaspy.

Even using the master vaspy branch, I can't run the sample code above without producing the error.

However, whatever is causing this trouble seems to be related to the charges information being stored. Changing line 381 in readers.py to (from checkout a81089fea7b743c6d2aefc154e7a2f7e473a3d46):

self.results['charges'] = [None for atom in self.atoms]

Seems to resolve the issue. However, this requires a change in the ASE database code to change this format into an array (to allow the list of Nones to be viewed as atoms as well as be managed by the database), so this isn't a good fix.

I can't figure out a better solution at the moment. I'll wait and see if anyone else reports the issue.

devonwa commented 8 years ago

Running your test doesn't work for me either. Trace:

Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "/opt/kitchingroup/vasp-5.3.5/ase-s16/ase/db/core.py", line 284, in get
    rows = list(self.select(selection, limit=2, **kwargs))
  File "/opt/kitchingroup/vasp-5.3.5/ase-s16/ase/db/core.py", line 397, in select
    limit=limit, offset=offset, sort=sort):
  File "/opt/kitchingroup/vasp-5.3.5/ase-s16/ase/db/sqlite.py", line 531, in _select
    yield self._convert_tuple_to_row(values)
  File "/opt/kitchingroup/vasp-5.3.5/ase-s16/ase/db/sqlite.py", line 362, in _convert_tuple_to_row
    dct['charges'] = deblob(values[24])
  File "/opt/kitchingroup/vasp-5.3.5/ase-s16/ase/db/sqlite.py", line 626, in deblob
    array = np.frombuffer(buf, dtype)
ValueError: buffer size must be a multiple of element size

My ASE is from the server. Vaspy from the current commit + your write_db update pull request.

One more important note is that after the write_db call, the calc has been changed in some way. I cannot do calc.view() after the call, though it works before the call.

Edit: calc.view() never works again after the write_db call, even in code blocks that don't include write_db.

jboes commented 8 years ago

The calculation is altered because the DB.db file is being "corrupted" in some way.

I would be curious to know if you get the same error with the dummy example using the master branch (no db_write update).

In the mean time, you may be forced to use my own solution which will looks like changing line 381 in reader.py to something like:

self.results['charges'] = np.array([None for atom in self.atoms])

Note that making this change will prevent you from viewing atoms objects with results attached to the i.e.

atoms = calc.get_atoms()
view(atoms)
devonwa commented 8 years ago

Same thing happens on the master branch. For others: my only change in the test script was to include fname as calc.write_db(fname="vasp-github-main.db")

The patch to line 381 of reader.py worked for me.