def create_calc(self, params): body = getBodyJson() if 'cjson' not in body and ('fileId' not in body or 'format' not in body): raise RestException('Either cjson or fileId is required.') user = getCurrentUser() cjson = body.get('cjson') props = body.get('properties', {}) molecule_id = body.get('moleculeId', None) geometry_id = body.get('geometryId', None) public = body.get('public', True) notebooks = body.get('notebooks', []) image = body.get('image') input_parameters = body.get('input', {}).get('parameters') if input_parameters is None: input_parameters = body.get('inputParameters', {}) file_id = None file_format = body.get('format', 'cjson') if 'fileId' in body: file = File().load(body['fileId'], user=getCurrentUser()) file_id = file['_id'] cjson = self._file_to_cjson(file, file_format) if molecule_id is None: mol = create_molecule(json.dumps(cjson), 'cjson', user, public, parameters=input_parameters) molecule_id = mol['_id'] calc = CalculationModel().create_cjson( user, cjson, props, molecule_id, geometry_id=geometry_id, image=image, input_parameters=input_parameters, file_id=file_id, notebooks=notebooks, public=public) cherrypy.response.status = 201 cherrypy.response.headers['Location'] \ = '/calculations/%s' % (str(calc['_id'])) return CalculationModel().filter(calc, user)
def ingest_calc(self, calculation, body, detectBonds=None): self.requireParams(['fileId', 'format'], body) file = File().load(body['fileId'], user=getCurrentUser()) cjson = self._file_to_cjson(file, body['format']) calc_props = calculation['properties'] # The calculation is no longer pending if 'pending' in calc_props: del calc_props['pending'] # Add bonds if they were not there already if detectBonds is None: detectBonds = False bonds = cjson.get('bonds') if bonds is None and detectBonds: new_cjson = openbabel.autodetect_bonds(cjson) if new_cjson.get('bonds') is not None: cjson['bonds'] = new_cjson['bonds'] calculation['properties'] = calc_props calculation['cjson'] = cjson calculation['fileId'] = file['_id'] image = body.get('image') if image is not None: calculation['image'] = image scratch_folder_id = body.get('scratchFolderId') if scratch_folder_id is not None: calculation['scratchFolderId'] = scratch_folder_id return CalculationModel().save(calculation)
def find_calc(self, moleculeId=None, geometryId=None, imageName=None, inputParameters=None, inputGeometryHash=None, name=None, inchi=None, inchikey=None, smiles=None, formula=None, creatorId=None, pending=None, limit=None, offset=None, sort=None): return CalculationModel().findcal( molecule_id=moleculeId, geometry_id=geometryId, image_name=imageName, input_parameters=inputParameters, input_geometry_hash=inputGeometryHash, name=name, inchi=inchi, inchikey=inchikey, smiles=smiles, formula=formula, creator_id=creatorId, pending=pending, limit=limit, offset=offset, sort=sort, user=getCurrentUser())
def ingest_calc(self, calculation, body, detectBonds=None): self.requireParams(['fileId', 'format'], body) file = File().load(body['fileId'], user=getCurrentUser()) cjson = self._file_to_cjson(file, body['format']) calc_props = calculation['properties'] # The calculation is no longer pending if 'pending' in calc_props: del calc_props['pending'] # Add bonds if they were not there already if detectBonds is None: detectBonds = False bonds = cjson.get('bonds') if bonds is None and detectBonds: new_cjson = openbabel.autodetect_bonds(cjson) if new_cjson.get('bonds') is not None: cjson['bonds'] = new_cjson['bonds'] calculation['properties'] = calc_props calculation['cjson'] = cjson calculation['fileId'] = file['_id'] image = body.get('image') if image is not None: calculation['image'] = image code = body.get('code') if code is not None: calculation['code'] = code scratch_folder_id = body.get('scratchFolderId') if scratch_folder_id is not None: calculation['scratchFolderId'] = scratch_folder_id # If this was a geometry optimization, create a geometry from it task = parse('input.parameters.task').find(calculation) if task and task[0].value == 'optimize': moleculeId = calculation.get('moleculeId') provenanceType = 'calculation' provenanceId = calculation.get('_id') # The cjson will be whitelisted geometry = GeometryModel().create(getCurrentUser(), moleculeId, cjson, provenanceType, provenanceId) calculation['optimizedGeometryId'] = geometry.get('_id') return CalculationModel().save(calculation)
def add_notebooks(self, calculation, notebooks): notebooks = notebooks.get('notebooks') if notebooks is not None: CalculationModel().add_notebooks(calculation, notebooks)