Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct property map "_settings" example #18

Open
ipcamit opened this issue Jun 1, 2022 · 2 comments
Open

Correct property map "_settings" example #18

ipcamit opened this issue Jun 1, 2022 · 2 comments

Comments

@ipcamit
Copy link
Collaborator

ipcamit commented Jun 1, 2022

Can anyone provide working example of _settings property map keys?
I deviced the following from source code doc strings

property_map = {
    'energy-forces': {
        # ColabFit name: {'field': ASE field name, 'units': str}
        'energy':   {'field': 'Energy',  'units': 'eV'},
        'forces':   {'field': 'forces',  'units': 'eV/Ang'},
        # 'stress':   {'field': 'virial',  'units': 'GPa'},
        # 'per-atom': {'field': 'per-atom', 'units': None},
        '_settings': {
            '_method': 'VASP',
            '_description': 'A static VASP calculation',
            '_files': None,
            '_labels': ['Monkhorst-Pack'],
            'xc-functional': {'field': 'xcf', 'units': None}
        }
    }
}

But I get the following error in insert_data class

AttributeError                            Traceback (most recent call last)
Input In [9], in <module>
      1 ids = list(
----> 2     client.insert_data(
      3         image_list,
      4         property_map=property_map,
      5         generator=False,
      6         verbose=True,
      7     )
      8 )

File ~/Projects/COLABFIT/colabfit-tools/colabfit/tools/database.py:362, in MongoDatabase.insert_data(self, configurations, property_map, transform, generator, verbose)
    360 for pdict in pdict_list:
    361     print(pdict)
--> 362     for k, pd in pdict.items():
    363         if k in ignore_keys:
    364             continue

AttributeError: 'str' object has no attribute 'items'
@jvita
Copy link
Member

jvita commented Jun 1, 2022

Try this instead:

property_map = {
    'energy-forces': [{
        # ColabFit name: {'field': ASE field name, 'units': str}
        'energy':   {'field': 'Energy',  'units': 'eV'},
        'forces':   {'field': 'forces',  'units': 'eV/Ang'},
        # 'stress':   {'field': 'virial',  'units': 'GPa'},
        # 'per-atom': {'field': 'per-atom', 'units': None},
        '_settings': {
            '_method': 'VASP',
            '_description': 'A static VASP calculation',
            '_files': None,
            '_labels': ['Monkhorst-Pack'],
            'xc-functional': {'field': 'xcf', 'units': None}
        }
    }]
}

Awhile back we changed the property map to be able to accept multiple maps for a single property type, so it's expecting property_map['energy-forces-stress'] to be a list of dictionaries.

You may also need to remove the underscores from _method, _description, _files, and _labels. We changed this in recent versions of the code, but I'm not sure what version you're working with.

EDIT: I'll leave this issue open as a reminder that I need to go through the docstrings to make sure they're up to date.

@ipcamit
Copy link
Collaborator Author

ipcamit commented Jun 1, 2022

Thanks, that solves it. I am using the latest version, master branch (aa2d1e3). I couldnt find updated version in documentation so i used the function doc-string in colabfit-tools/tools/dataset.py for hint, and that function still lists older format
Line 285 - 302

     property_map = {
                            'energy-forces-stress': {
                                # ColabFit name: {'field': ASE field name, 'units': str}
                                'energy':   {'field': 'energy',  'units': 'eV'},
                                'forces':   {'field': 'forces',  'units': 'eV/Ang'},
                                'stress':   {'field': 'virial',  'units': 'GPa'},
                                'per-atom': {'field': 'per-atom', 'units': None},

                                '_settings': {
                                    '_method': 'VASP',
                                    '_description': 'A static VASP calculation',
                                    '_files': None,
                                    '_labels': ['Monkhorst-Pack'],

                                    'xc-functional': {'field': 'xcf', 'units': None}
                                }
                            }
                        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants