def backendFind(database, user, filter, sort, limit, keys, omit_keys): box = StructureBox(Backend(database=database, user=user)) atoms_it = box.find( auth_token="", filter=json.loads(b64decode(filter)), sort=json.loads(b64decode(sort)), limit=limit, keys=json.loads(b64decode(keys)), omit_keys=json.loads(b64decode(omit_keys)), ) atoms_dcts_list = [atoms2dict(atoms, True) for atoms in atoms_it] print("204:" + b64encode(json.dumps(atoms_dcts_list)))
import numpy as np from ase.lattice import bulk from ase.calculators.singlepoint import SinglePointCalculator from abcd.structurebox import StructureBox from abcd.authentication import Credentials import mongobackend.mongobackend as mongobackend box = StructureBox(mongobackend.MongoDBBackend('localhost', 27017)) token = box.authenticate(Credentials('martin')) box.remove(token, {}, False) N = 10 for i in range(N): atoms = bulk('Si', crystalstructure='diamond', a=5.43, cubic=True) atoms.rattle() # simulate a calculation with random results e = np.random.uniform() f = np.random.uniform(size=3 * len(atoms)).reshape((len(atoms), 3)) s = np.random.uniform(size=9).reshape((3, 3)) calc = SinglePointCalculator(atoms, energy=e, forces=f, stress=s) atoms.set_calculator(calc) f = atoms.get_forces() e = atoms.get_potential_energy() # add some arbitrary data atoms.info['integer_info'] = 42 atoms.info['real_info'] = 217 atoms.info['config_type'] = 'diamond'
def backendUpdate(database, user, atoms, upsert, replace): box = StructureBox(Backend(database=database, user=user)) atoms_dcts_list = json.loads(b64decode(atoms)) atoms_list = [dict2atoms(atoms_dct, plain_arrays=True) for atoms_dct in atoms_dcts_list] res = box.update(auth_token="", atoms=atoms_list, upsert=upsert, replace=replace) print("221:" + b64encode(json.dumps(res.__dict__)))
def backendRemove(database, user, filter, just_one): box = StructureBox(Backend(database=database, user=user)) query = json.loads(b64decode(filter)) res = box.remove(auth_token="", filter=query, just_one=just_one) print("222:" + b64encode(json.dumps(res.__dict__)))
def backendInsert(database, user, atoms): box = StructureBox(Backend(database=database, user=user)) atoms_dcts_list = json.loads(b64decode(atoms)) atoms_list = [dict2atoms(atoms_dct, plain_arrays=True) for atoms_dct in atoms_dcts_list] res = box.insert(auth_token="", atoms=atoms_list) print("220:" + b64encode(json.dumps(res.__dict__)))
def backendList(user): box = StructureBox(Backend(user=user)) dbs = box.list("") print("202:" + b64encode(json.dumps(dbs)))
def backendRemoveKeys(database, user, filter, keys): box = StructureBox(Backend(database=database, user=user)) res = box.remove_keys(auth_token="", filter=json.loads(b64decode(filter)), keys=json.loads(b64decode(keys))) print("224:" + b64encode(json.dumps(res.__dict__)))
def backendAddKeys(database, user, filter, kvp): box = StructureBox(Backend(database=database, user=user)) res = box.add_keys(auth_token="", filter=json.loads(b64decode(filter)), kvp=json.loads(b64decode(kvp))) print("223:" + b64encode(json.dumps(res.__dict__)))
import numpy as np from ase.lattice import bulk from ase.calculators.singlepoint import SinglePointCalculator from abcd.structurebox import StructureBox from abcd.authentication import Credentials import mongobackend.mongobackend as mongobackend box = StructureBox(mongobackend.MongoDBBackend('localhost', 27017)) token = box.authenticate(Credentials('martin')) box.remove(token, {}, False) N = 10 for i in range(N): atoms = bulk('Si', crystalstructure='diamond', a=5.43, cubic=True) atoms.rattle() # simulate a calculation with random results e = np.random.uniform() f = np.random.uniform(size=3*len(atoms)).reshape((len(atoms), 3)) s = np.random.uniform(size=9).reshape((3, 3)) calc = SinglePointCalculator(atoms, energy=e, forces=f, stress=s) atoms.set_calculator(calc) f = atoms.get_forces() e = atoms.get_potential_energy() # add some arbitrary data atoms.info['integer_info'] = 42 atoms.info['real_info'] = 217