def __init__(self, ontology=None, classes=None, version='0.1', collid=None): if ontology is None: self.onto = get_ontology() self.onto.load() elif isinstance(ontology, str): self.onto = get_ontology(ontology) self.onto.load() else: self.onto = ontology self.version = version self.iri = self.onto.base_iri self.namespace = self.onto.base_iri.rstrip('#') self.coll = dlite.Collection(collid) if classes is None: classes = self.onto.classes() elif isinstance(classes, str): classes = [classes] for cls in classes: self.add_class(cls)
def __init__(self, ontology=None, classes=None, version='0.1', collid=None): if ontology is None: self.onto = get_ontology() self.onto.load() elif isinstance(ontology, str): self.onto = get_ontology(ontology) self.onto.load() else: self.onto = ontology self.version = version self.iri = self.onto.base_iri self.namespace = self.onto.base_iri.rstrip('#') self.coll = dlite.Collection(collid) # To avoid infinite recursion when adding cyclic dependent entities # we keep track of all labels we add (or are going to add) to the # collection self.labels = set() if classes is None: classes = self.onto.classes() elif isinstance(classes, str): classes = [classes] for cls in classes: self.add_class(cls)
def map_app2common(inst, metacoll, out_id=None): """Maps atom structure `inst` from our application representation (based on a not explicitly stated ontology) to the common EMMO-based representation in `metacoll`. Parameters ---------- inst : Instance of http://sintef.no/meta/soft/0.1/Atoms Input atom structure. metacoll : Collection Collection of EMMO-based metadata generated from the ontology. out_id : None | string An optional id associated with the returned collection. Returns ------- atcoll : Collection New collection with the atom structure represented as instances of metadata in `metacoll`. Notes ----- We use lowercase and underscore notation for the individuals. """ infodict = dict(inst.info) # make dict out of the info field # Create new collection representing `inst` in our case ontology atcoll = dlite.Collection(out_id) # Get metadata from metacoll Crystal = metacoll['Crystal'] UnitCell = metacoll['CrystalUnitCell'] EBondedAtom = metacoll['BondedAtom'] # Instanciate the structure crystal = Crystal([]) crystal.spacegroup = infodict['spacegroup'] atcoll.add('crystal', crystal) unit_cell = UnitCell([3, 3, 36]) unit_cell.lattice_vector = inst.cell atcoll.add('unit_cell', unit_cell) atcoll.add_relation('crystal', 'hasSpatialDirectPart', 'unit_cell') for i in range(inst.natoms): label = 'atom%d' % i a = EBondedAtom([3]) a.AtomicNumber = inst.numbers[i] a.Position = inst.positions[i] atcoll.add(label, a) atcoll.add_relation('unit_cell', 'hasSpatialDirectPart', label) return atcoll
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Step 3 - load atom structure and represent it using our metadata framework -------------------------------------------------------------------------- In this step we uses the Atomistic Simulation Environment (ASE) to load a atomistic Al-Fe4Al13 interface structure from a cif file and represents it using the metadata defined in step 2. """ import ase import ase.io from ase.spacegroup import Spacegroup import dlite from step2_define_atoms import DLiteAtoms # Load atom structure from cif file and convert it to a DLiteAtoms object at = ase.io.read('../vertical/Al-Fe4Al13.cif') atoms = dlite.objectfactory(at, cls=DLiteAtoms, instanceid='atoms_Al-Fe4Al13') # Create a new collection for data instances coll = dlite.Collection('usercase_appdata') coll.add('Atoms', atoms.dlite_meta) coll.add('atoms', atoms.dlite_inst) coll.save('json', 'usercase_appdata.json', 'mode=w')
import os import importlib import dlite from dlite import Instance from global_dlite_state_mod1 import assert_exists_in_module thisdir = os.path.abspath(os.path.dirname(__file__)) assert len(dlite.istore_get_uuids()) == 3 # 3 Hardcoded dlite instances coll = dlite.Collection() # (1) assert dlite.has_instance(coll.uuid) assert coll.uuid in dlite.istore_get_uuids() assert len(dlite.istore_get_uuids()) == 3 + 1 # Must exist in imported dlite in different module (mod1) assert_exists_in_module(coll.uuid) url = 'json://' + thisdir + '/MyEntity.json' + "?mode=r" e = Instance.create_from_url(url) # (2) assert len(dlite.istore_get_uuids()) == 3 + 2 inst1 = Instance.create_from_metaid(e.uri, [3, 2]) # (3) assert len(dlite.istore_get_uuids()) == 3 + 3 inst2 = Instance.create_from_metaid(e.uri, (3, 4), 'myinst') # (4) assert len(dlite.istore_get_uuids()) == 3 + 4 del inst1 assert len(dlite.istore_get_uuids()) == 3 + 3
# from ontopy import get_ontology # will soon release on pypi the bigg # structure change in emmo-python from ontopy import get_ontology import dlite dlite.storage_path.append(f'../molecules/*.json') dlite.storage_path.append(f'../reaction/*.json') # input from ontologist onto = get_ontology('https://raw.githubusercontent.com' '/BIG-MAP/BattINFO/master/battinfo.ttl').load() molecule_collection = dlite.Collection('json:../molecules/atomscaledata.json' '?mode=r#molecules', 0) # not intuituve reaction_collection = dlite.Collection('json:../reaction/reactiondata.json' '?mode=r#reactions', 0) # not intuituve ''' for inst in molecule_collection.get_instances(): map: Molecule -> onto.Molecule Reaction -> onto.ChemicalReaction Reactant -> onto.Reactant Product -> onto.Product Energy -> onto.Energy # But we are talking about different energies here... '''
unit_cell = UnitCell([3, 3, 36]) unit_cell.lattice_vector = inst.cell atcoll.add('unit_cell', unit_cell) atcoll.add_relation('crystal', 'has_spatial_direct_part', 'unit_cell') for i in range(inst.natoms): label = 'atom%d' % i a = EBondedAtom([3]) a.atomic_number = inst.numbers[i] a.position = inst.positions[i] atcoll.add(label, a) atcoll.add_relation('unit_cell', 'has_spatial_direct_part', label) return atcoll # Load metadata collection from step 1 metacoll = dlite.Collection( 'json://usercase_metadata.json?mode=r#usercase_ontology', True) # Load dlite-representation of atoms structure from step 3 coll = dlite.Collection('json://usercase_appdata.json?mode=r#usercase_appdata', False) inst = coll.get('atoms') # Do the mapping new = map_app2common(inst, metacoll) # Append the new atoms collection to the storage new.save('json://usercase_data.json?mode=w')
instance of Molecule. ASE is used to calculate the molecule ground state energy. """ atoms = ase.io.read(filename) # ASE Atoms object atoms.calc = EMT() molname = Path(filename).stem inst = Molecule(dims=[len(atoms), 3], id=molname) # DLite instance inst.name = molname inst.positions = atoms.positions inst.symbols = atoms.get_chemical_symbols() inst.masses = atoms.get_masses() inst.groundstate_energy = atoms.get_potential_energy() return inst Molecule = dlite.Instance.create_from_url(f'json://{entitydir}/Molecule.json') # Create a new collection and populate it with all molecule structures coll = dlite.Collection(id='molecules') for filename in moldir.glob('*.xyz'): molname = filename.stem mol = readMolecule(filename) coll.add(label=molname, inst=mol) coll.save('json', f'{thisdir}/atomscaledata.json', 'mode=w') # Change this example so that the calculation is done on the entities # from the collection of Molecules (with only info about chemical structure) # Read and populate the Molecule