Пример #1
0
 def validate_gro_file(self, filename):
     """ Validate gro file, this is the first step and we save the molecule object """
     os.chdir(self._folder)
     self.gro_filename = filename
     try:
         m = Molecule(self.gro_filename)
         pdb_string = '\n'.join(m.write_pdb(range(m.na)))
         ret = {
             'success': True,
             'n_shots': len(m),
             'n_atoms': m.na,
             'pdbString': pdb_string,
         }
     except Exception as e:
         print(e)
         ret = {'success': False, 'error': str(e)}
     return ret
Пример #2
0
 def get_target_objective_data(self, target_name, opt_iter):
     """ Read objective data for a target and an optimization iteration from the tmp folder """
     res = {}
     target_options = self.input_options['tgt_opts'].get(target_name, None)
     if target_options is None:
         res['error'] = f"target {target_name} not found"
         print(f"get_target_objective_data: {res['error']}")
         return res
     # check the tmp folder for this target
     folder = os.path.join(self.tmp_folder, target_name,
                           f'iter_{opt_iter:04d}')
     if not os.path.isdir(folder):
         res['error'] = f"tmp folder {folder} not found"
         print(f"get_target_objective_data: {res['error']}")
         return res
     # get target type specific objective information
     target_type = target_options['type']
     if target_type.lower().startswith('abinitio'):
         # read energy compare data
         energy_compare_file = os.path.join(folder, 'EnergyCompare.txt')
         if not os.path.isfile(energy_compare_file):
             res['error'] = f"file {energy_compare_file} not found"
             print(f"get_target_objective_data: {res['error']}")
             return res
         energy_compare_data = np.loadtxt(energy_compare_file)
         res['qm_energies'] = energy_compare_data[:, 0].tolist()
         res['mm_energies'] = energy_compare_data[:, 1].tolist()
         res['diff'] = energy_compare_data[:, 2].tolist()
         res['weights'] = energy_compare_data[:, 3].tolist()
         # read molecule geometry
         mol_file = os.path.join(folder, 'coords.xyz')
         m = Molecule(mol_file)
         # generate pdb string
         if 'resname' not in m.Data:
             m.Data['resname'] = ['MOL'] * m.na
             m.Data['resid'] = [1] * m.na
         res['pdbString'] = '\n'.join(m.write_pdb(range(m.na)))
     else:
         res['error'] = f"get objective data for target type {target_type} not implemented"
         print(f"get_target_objective_data: {res['error']}")
         return res
     return res
 def validate_coords_file(self, filename):
     """ Validate coords xyz file, this is the first step and we save the molecule object """
     os.chdir(self._folder)
     self.coords_filename = filename
     try:
         m = Molecule(self.coords_filename)
         # generate pdb string
         if 'resname' not in m.Data:
             m.Data['resname'] = ['MOL'] * m.na
             m.Data['resid'] = [1] * m.na
         pdb_string = '\n'.join(m.write_pdb(range(m.na)))
         ret = {
             'success': True,
             'n_shots': len(m),
             'n_atoms': m.na,
             'pdbString': pdb_string,
         }
     except Exception as e:
         print(e)
         ret = {'success': False, 'error': str(e)}
     return ret