示例#1
0
def get_cuds_collection(include_parent=True):
    """Returns Collection holding the CUDS metadata.

    If `include_parent` is true, the generated CUDS element entities
    will also include attributes of their parent.

    Note, this requires softpy.
    """
    import softpy
    with open(os.path.join(thisdir, 'metadata', 'cuba.yml')) as f:
        cuba = yaml.load(f.read())
    with open(os.path.join(thisdir, 'metadata', 'simphony_metadata.yml')) as f:
        cuds = yaml.load(f.read())
    entities, relations = generate_cuds_entities(cuds,
                                                 cuba,
                                                 include_parent=include_parent)

    uuid = softpy.uuid_from_entity('CUDS', '1.0', 'http://emmc.info/meta')
    c = softpy.Collection(uuid=uuid)
    c.name = 'CUDS'
    c.version = cuds['VERSION']
    for jsondict in entities:
        entity = softpy.entity(jsondict)
        c.add(entity.name, entity)
    for relation in relations:
        c.add_relation(*relation)

    # Save all metadata in a database
    s = StringIO() if sys.version_info.major >= 3 else BytesIO()
    json.dump(entities, s)
    s.seek(0)
    softpy.register_metadb(softpy.JSONMetaDB(s))
    s.close()

    return c
示例#2
0
        },
        {
            "name": "masses",
            "type": "double",
            "unit": "u",
            "dims": [
                "N"
            ],
            "description": "Mass of each atom"
        }
    ]
}
"""

# Create new Structure entity based on the metadata
Structure = softpy.entity(metadata)

# Create a empty Structure instance
s = Structure()
s.structure = 'water'
s.symbols = ['H', 'H', 'O']
s.spacegroup = 1
s.total_energy = 446.32
s.masses = np.array([1., 1., 16.])

s.soft_internal_check_dimension_sizes()

# Write the structure to file
with softpy.Storage('hdf5', 'softpy-test-factory.h5') as storage:
    storage.save(s)
示例#3
0
import sys
import re
import math
import warnings
import json
import ast

from vasp_outcar import CONTCAR, OUTCAR

thisdir = os.path.abspath(os.path.dirname(__file__))
entitydir = os.path.join(thisdir, '../entities')

try:
    import softpy
    HAVE_SOFT = True
    BaseDFTData = softpy.entity(
        open(os.path.join(entitydir, 'eu.nanosim.vasp.dftdata.json')))
except ImportError:
    warnings.warn('SOFT is not available')
    HAVE_SOFT = False
    BaseDFTData = object

if sys.version_info.major >= 3:
    basestring = str


class VASP_DATA(object):
    """
    Read data from OUTCAR-files.
    The root directory with subdirectories must be set up in as specific
    manner, for info see manual.
    The CONTCAR and OUTCAR file must be in the corresponding directories.
示例#4
0
import sys
import re
import math
import warnings
import json
import ast

from vasp_outcar import CONTCAR, OUTCAR

thisdir = os.path.abspath(os.path.dirname(__file__))
entitydir = os.path.join(thisdir, '../entities')

try:
    import softpy
    HAVE_SOFT = True
    BaseDFTData = softpy.entity(
        open(os.path.join(entitydir, 'eu.nanosim.vasp.dftdata.json')))
except ImportError:
    warnings.warn('SOFT is not available')
    HAVE_SOFT = False
    BaseDFTData = object

if sys.version_info.major >= 3:
    basestring = str


class VASP_DATA(object):
    """
    Read data from OUTCAR-files.
    The root directory with subdirectories must be set up in as specific
    manner, for info see manual.
    The CONTCAR and OUTCAR file must be in the corresponding directories.
示例#5
0
thisdir = os.path.dirname(__file__)


coll = softpy.Collection()
assert coll.get_num_entities() == 0
assert coll.get_num_relations() == 0

coll.name = 'foo'
assert coll.name == 'foo'

coll.version = '1.0'
assert coll.version == '1.0'

with open(os.path.join(thisdir, 'person.json')) as f:
    Person = softpy.entity(f)

jack = Person(name='Jack', age=42, skills=[])
alda = Person(name='Alda', age=39, skills=['foo'])
fred = Person(name='Fred', age=12, skills=['bar'])
coll.add('Jack', jack)
coll.add('Alda', alda)
coll.add('Fred', fred)
assert coll.get_num_entities() == 3

coll.add_relation('Jack', 'loves', 'Alda')
coll.add_relation('Jack', 'loves', 'Fred')
coll.add_relation('Jack', 'husband_of', 'Alda')
coll.add_relation('Jack', 'father_of', 'Fred')

assert coll.find_relations('Jack', 'loves') == {'Fred', 'Alda'}
示例#6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

import os

import softpy


thisdir = os.path.dirname(__file__)


Person = softpy.entity(open(os.path.join(thisdir, "person.json")))

jack = Person()


coll = softpy.Collection()
assert len(coll) == 0
coll["jack"] = jack
# assert len(coll) == 1
示例#7
0
jsondb = softpy.JSONMetaDB('metadb.json')
jsondb.clear()
assert jsondb.has('Person', '0.2.4', 'http://sintef.no/meta/soft') is False
jsondb.insert(open('person.json'))
assert jsondb.has('Person', '0.2.4', 'http://sintef.no/meta/soft') is True
types = jsondb.types()
assert types[0] == ('Person', '0.2.4', 'http://sintef.no/meta/soft')

softpy.register_metadb(jsondb)

meta = softpy.Metadata(name='Person',
                       version='0.2.4',
                       namespace='http://sintef.no/meta/soft')

Person = softpy.entity(name='Person',
                       version='0.2.4',
                       namespace='http://sintef.no/meta/soft')
jack = Person(name='Jack', age=42, skills=['foo', 'bar'])
assert jack.soft_metadata == meta
jsondb.close()

try:
    import pymongo
except ImportError:
    import warnings
    warnings.warn('pymongo not installed - skipping mongodb test...')
else:
    mongodb = softpy.MongoMetaDB('mongodb://localhost:27017/', 'metadb_test',
                                 'metadata')
    mongodb.clear()
    assert mongodb.has('Person', '0.2.4',
示例#8
0
文件: atoms.py 项目: NanoSim/Porto
import warnings
import pickle
import ast
import base64

import numpy as np
import ase
import ase.constraints
from ase.calculators.emt import EMT
from ase.lattice.spacegroup import Spacegroup, crystal
from ase.visualize import view
import softpy
import dill


BaseSoftAtoms = softpy.entity(open('atoms.json'))


class SoftAtoms(BaseSoftAtoms, ase.Atoms):
    """An ase.Atoms subclass behaving as a SOFT entity.

    Takes the same arguments as ase.Atoms with the following additions:

    symbols - same meaning as in Atoms, except that it also can be an
              existing Atoms object
    uuid    - optional, id of instance to load from driver
    driver  - optional, driver to use for loading data: "json", "hdf5", "mongo"
    uri     - optional, from where to load data
    options - optional, additional options passed to the driver
    """
    def __new__(cls, symbols=None, uuid=None, driver=None, uri=None,
示例#9
0
thisdir = os.path.dirname(__file__)


coll = softpy.Collection()
assert coll.get_num_entities() == 0
assert coll.get_num_relations() == 0

coll.name = 'foo'
assert coll.name == 'foo'

coll.version = '1.0'
assert coll.version == '1.0'


Person = softpy.entity(open(os.path.join(thisdir, 'person.json')))
jack = Person(name='Jack', age=42, skills=[])
alda = Person(name='Alda', age=39, skills=['foo'])
fred = Person(name='Fred', age=12, skills=['bar'])
coll.register_entity('Jack', jack)
coll.register_entity('Alda', alda)
coll.register_entity('Fred', fred)
assert coll.get_num_entities() == 3

coll.add_relation('Jack', 'loves', 'Alda')
coll.add_relation('Jack', 'loves', 'Fred')
coll.add_relation('Jack', 'husband_of', 'Alda')
coll.add_relation('Jack', 'father_of', 'Fred')

assert coll.find_relations('Jack', 'loves') == {'Fred', 'Alda'}
assert coll.find_relations('Alda', '^loves') == {'Jack'}
示例#10
0
        },
        {
            "name": "masses",
            "type": "double",
            "unit": "u",
            "dims": [
                "N"
            ],
            "description": "Mass of each atom"
        }
    ]
}
"""

# Create new Structure entity based on the metadata
Structure = softpy.entity(metadata)

# Create a empty Structure instance
s = Structure()
s.structure = 'water'
s.symbols = ['H', 'H', 'O']
s.spacegroup = 1
s.total_energy = 446.32
s.masses = np.array([1., 1., 16.])

s.soft_internal_check_dimension_sizes()

# Write the structure to file
with softpy.Storage('hdf5', 'softpy-test-factory.h5') as storage:
    storage.save(s)
示例#11
0
import warnings
import pickle
import ast
import base64

import numpy as np
import ase
import ase.constraints
from ase.calculators.emt import EMT
from ase.lattice.spacegroup import Spacegroup, crystal
from ase.visualize import view
import softpy
import dill

BaseSoftAtoms = softpy.entity(open('atoms.json'))


class SoftAtoms(BaseSoftAtoms, ase.Atoms):
    """An ase.Atoms subclass behaving as a SOFT entity.

    Takes the same arguments as ase.Atoms with the following additions:

    symbols - same meaning as in Atoms, except that it also can be an
              existing Atoms object
    uuid    - optional, id of instance to load from driver
    driver  - optional, driver to use for loading data: "json", "hdf5", "mongo"
    uri     - optional, from where to load data
    options - optional, additional options passed to the driver
    """
    def __new__(cls,
示例#12
0
thisdir = os.path.dirname(__file__)

# Load SOFT metadata database
softpy.register_metadb(softpy.JSONDirMetaDB(os.path.join(thisdir, 'metadata')))

# Load CUDS metadata database (created by softcuds.py)
softpy.register_metadb(
    softpy.JSONDirMetaDB(
        os.path.join(thisdir, 'metadata', 'cuds_entities', '1.0')))

# Read cif data
cf = ReadCif('VO2_rutile.cif')
rut = cf['VO2_rut_ini']

# Create a Python class representation of cifdata-0.1
CifData = softpy.entity('cifdata', '0.1', 'http://emmc.info/meta')

# Create uninitialised CifData instance
cifdata = CifData()

# Initialise the instance from the cif file
cifkeys = [k.lower() for k in rut.keys()]  # newer versions of PyCifRW
# changed all keys to lower-case
for name in cifdata.soft_get_property_names():
    tag = '_' + name.lower()
    if tag in cifkeys:
        value = rut[tag]
    elif name == 'atom_site_type_symbol':
        value = [
            re.match('[A-Z][a-z]{0,2}', l).group()
            for l in rut['_atom_site_label']
示例#13
0
import softpy

Initial = softpy.entity(open('initial.json'))

i = Initial(dimension_sizes=[50,50])
i.dt = 2.0e-3
i.startt = 0.0
i.endt = 2.0
i.nu = 1.0e-2
i.sample_interval = 1.0

s = softpy.Storage(driver='hdf5', uri='init.h5')
s.save(i)
s.close()
print(softpy.get_id(i));