def create_cjson(self,
                     user,
                     cjson,
                     props,
                     molecule_id=None,
                     image=None,
                     input_parameters=None,
                     file_id=None,
                     public=False,
                     notebooks=None):
        if notebooks is None:
            notebooks = []

        calc = {'cjson': cjson, 'properties': props, 'notebooks': notebooks}
        if molecule_id:
            calc['moleculeId'] = molecule_id
        if file_id:
            calc['fileId'] = file_id
        if image is not None:
            calc['image'] = image
        if input_parameters is not None:
            calc.setdefault('input', {})['parameters'] = input_parameters
            calc.setdefault(
                'input',
                {})['parametersHash'] = oc.hash_object(input_parameters)

        calc['creatorId'] = user['_id']
        self.setUserAccess(calc, user=user, level=AccessType.ADMIN)
        if public:
            self.setPublic(calc, True)

        return self.save(calc)
    def create_cjson(self, user, cjson, props, molecule_id= None,
                     image=None, input_parameters=None,
                     file_id = None, public=False, notebooks=None):
        if notebooks is None:
            notebooks = []

        calc = {
            'cjson': cjson,
            'properties': props,
            'notebooks': notebooks
        }
        if molecule_id:
            calc['moleculeId'] = molecule_id
        if file_id:
            calc['fileId'] = file_id
        if image is not None:
            calc['image'] = image
        if input_parameters is not None:
            calc.setdefault('input', {})['parameters'] = input_parameters
            calc.setdefault('input', {})['parametersHash'] = oc.hash_object(input_parameters)

        self.setUserAccess(calc, user=user, level=AccessType.ADMIN)
        if public:
            self.setPublic(calc, True)

        return self.save(calc)
Beispiel #3
0
    def findcal(self, molecule_id=None, geometry_id=None, image_name=None,
                input_parameters=None, input_geometry_hash=None,
                name=None, inchi=None, inchikey=None, smiles=None,
                formula=None, creator_id=None, pending=None, limit=None,
                offset=None, sort=None, user=None):
        # Set these to their defaults if they are not already set
        limit, offset, sort = default_pagination_params(limit, offset, sort)

        query = {}

        # If a molecule id is specified it has higher priority
        if molecule_id:
            query['moleculeId'] = ObjectId(molecule_id)
        # Otherwise, if query parameters for the molecules are
        # specified, search for matching molecules first
        elif any((name, inchi, inchikey, smiles, formula)):
            params = {'offset': 0, 'limit': sys.maxsize}

            if name:
                params['name'] = name
            if inchi:
                params['inchi'] = inchi
            if inchikey:
                params['inchikey'] = inchikey
            if smiles:
                params['smiles'] = smiles
            if formula:
                params['formula'] = formula

            molecules = MoleculeModel().find_molecule(params)['results']
            molecule_ids = [molecule['_id'] for molecule in molecules]
            query['moleculeId'] = {'$in': molecule_ids}

        if geometry_id:
            # This is currently not being stored as an ObjectId
            query['geometryId'] = geometry_id

        if image_name:
            repository, tag = oc.parse_image_name(image_name)
            query['image.repository'] = repository
            query['image.tag'] = tag

        if input_parameters:
            input_json = json.loads(urllib.parse.unquote(input_parameters))
            query['input.parametersHash'] = oc.hash_object(input_json)

        if input_geometry_hash:
            query['input.geometryHash'] = input_geometry_hash

        if creator_id:
            query['creatorId'] = ObjectId(creator_id)

        if pending is not None:
            pending = toBool(pending)
            query['properties.pending'] = pending
            # The absence of the field mean the calculation is not pending ...
            if not pending:
                query['properties.pending'] = {
                    '$ne': True
                }

        fields = ['image', 'input', 'code',
                  'cjson', 'cjson.vibrations.modes', 'cjson.vibrations.intensities',
                  'cjson.vibrations.frequencies', 'properties', 'fileId', 'access',
                  'moleculeId', 'public']

        calcs = self.find(query, fields=fields, limit=limit,
                                 offset=offset, sort=sort)
        num_matches = calcs.collection.count_documents(query)

        calcs = self.filterResultsByPermission(calcs, user,
            AccessType.READ, limit=limit)
        calcs = [self.filter(x, user) for x in calcs]

        return search_results_dict(calcs, num_matches, limit, offset, sort)