Пример #1
0
 def from_mol(self) -> dict:
     if self.get('extension') in ('mol', 'sdf', 'mdl'):
         mol = Chem.MolFromMolBlock(self.get('block'),
                                    sanitize=True,
                                    removeHs=False,
                                    strictParsing=True)
     elif self.get('extension') in ('mol2', ):
         mol = Chem.MolFromMol2Block(self.get('block'),
                                     sanitize=True,
                                     removeHs=False)
     elif self.get('extension') in ('pdb', ):
         mol = Chem.MolFromPDBBlock(self.get('block'),
                                    sanitize=True,
                                    removeHs=False,
                                    proximityBonding=False)
     else:
         raise exc.HTTPClientError(
             f"Format {self.get('extension')} not supported")
     if self.get_bool('protons') is True:
         mol = AllChem.AddHs(mol)
     p = Params.from_mol(mol,
                         self.name,
                         generic=self.generic,
                         atomnames=self.atomnames)
     return self.to_dict(p)
Пример #2
0
def generate_report(request):
    """Generates xlsx report

    """
    try:
        user_id = request.user
        lang = rt.language(user_id)
    except KeyError:
        raise http_exc.HTTPUnauthorized()
    try:
        project = rt.get_state(user_id)._project_id
        # TODO remove test project
        if project is None:
            project = request.json_body['data']['project']
            rt.update_state(user_id, tool_id='forecast', project_id=project)
        wb = rt.get_wb(user_id)
        session = request.dbsession
        permission_tree = build_permission_tree(session, project_name=project)
        scenarios = get_scenarios(session, user_id, None)
        for scenario in scenarios:
            scenario['details'] = get_scenario_details(session, user_id, scenario['id'])

        options = reporting.get_options_data(config=wb.data_config, scenarios=scenarios)
        data = reporting.collect_report_data(options=options, permission_tree=permission_tree,
                                             container=wb.default_container, config=wb.data_config,
                                             entities_ids=wb.selection, lang=lang)
        reporting.create_report(request.json_body['data']['file_name'], data)

    except Exception:
        raise http_exc.HTTPClientError()
    else:
        return Response(json_body=json.dumps('Success'), content_type='application/json')
Пример #3
0
 def name(self) -> str:
     if 'name' in self.request.params:
         name = self.request.params['name']
         name = re.sub('\W', '', name)
         if len(name) != 3:
             raise exc.HTTPClientError(
                 f'{self.request.params["name"]} ("{name}") is not three letters long.'
             )
         else:
             return name
     else:
         return 'LIG'
Пример #4
0
 def ajacean(self) -> dict:
     try:
         mode = self.request.matchdict['mode']
         if mode == 'smiles':
             return self.from_smiles()
         elif mode == 'mol':
             return self.from_mol()
         elif mode == 'smiles_pdb':
             return self.from_pdb()
         else:
             raise exc.HTTPClientError(f'Unknown mode `{mode}`')
     except exc.HTTPError as error:
         self.request.response.status_code = error.status_code
         return {'error': f'{error.__class__.__name__}: {error}'}
     except Exception as error:
         log.exception(f'{error.__class__.__name__}: {error}')
         return {'error': f'{error.__class__.__name__}: {error}'}
Пример #5
0
def get_report_options(request):
    """Returns options for report

    """
    try:
        user_id = request.user
    except KeyError:
        raise http_exc.HTTPUnauthorized()
    try:
        # project = rt.get_state(user_id)._project_id
        wb = rt.get_wb(user_id)
        session = request.dbsession
        # permission_tree = build_permission_tree(session, project_name=project)
        # filters = {'authors': ['default_user'], 'period': [], 'criteria': []}
        scenarios = get_scenarios(session, user_id, None)
        for scenario in scenarios:
            scenario['details'] = get_scenario_details(session, user_id, scenario['id'])

        data = reporting.get_options_data(config=wb.data_config, scenarios=scenarios)
    except Exception:
        raise http_exc.HTTPClientError()
    else:
        return Response(json_body=json.dumps(data), content_type='application/json')
Пример #6
0
 def get(self, key):
     if key in self.request.params:
         return self.request.params[key]
     else:
         raise exc.HTTPClientError(
             f'Query parameter {key} was not provided.')