colabfit / colabfit-tools

Tools for constructing and manipulating datasets for fitting interatomic potentials
Other
6 stars 2 forks source link

Correct property map "_settings" example #18

Open ipcamit opened 2 years ago

ipcamit commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Thanks, that solves it. I am using the latest version, master branch (aa2d1e3b). 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}
                                }
                            }
                        }