def overlay_cp2k_settings(self, cp2k_settings: MutableMapping, psf: Optional[PSFContainer] = None) -> None: r"""Overlay **df** with all :math:`q`, :math:`\sigma` and :math:`\varepsilon` values from **cp2k_settings**.""" # noqa charge = cp2k_settings['input']['force_eval']['mm']['forcefield'][ 'charge'] charge_dict = { block['atom']: float(block['charge']) for block in charge } if psf is not None: psf_charge_dict = dict(zip(psf.atom_type, psf.charge)) for k, v in psf_charge_dict.items(): if k not in charge_dict: charge_dict[k] = v epsilon_s = Settings() # type: ignore[var-annotated] sigma_s = Settings() # type: ignore[var-annotated] # Check if the settings are qmflows-style generic settings lj = cp2k_settings.get('lennard-jones') or cp2k_settings.get( 'lennard_jones') if lj is not None: self._overlay_s_qmflows(cp2k_settings, sigma_s, epsilon_s) else: lj = cp2k_settings['input']['force_eval']['mm']['forcefield'][ 'nonbonded']['lennard-jones'] # noqa self._overlay_s_plams(lj, sigma_s, epsilon_s) self.set_charge(charge_dict) for unit, dct in epsilon_s.items(): self.set_epsilon_pairs(dct, unit=unit) for unit, dct in sigma_s.items(): self.set_sigma_pairs(dct, unit=unit)
def repr_Settings(self, obj: Settings, level: int) -> str: # noqa: N802 """Create a :class:`str` representation of a |plams.Settings| instance.""" n = len(obj) if not obj: return f'{obj.__class__.__name__}()' elif level <= 0: return '\n...' pieces: List[str] = [] indent = 4 * ' ' newlevel = level - 1 for k, v in islice(obj.items(), self.maxSettings): key = str(k) value = self.repr1(v, newlevel) pieces.append(f'\n{key}:') if type(obj) is type(value): pieces.append(f'{textwrap.indent(value, indent)}:') else: pieces.append(f'{textwrap.indent(value, indent)}') if n > self.maxSettings: pieces.append('\n...') ret = ''.join(pieces) if level == self.maxlevel: return f'{obj.__class__.__name__}(\n{textwrap.indent(ret[1:], indent)}\n)' return ret
def read_mol_folder(mol_dict: Settings) -> Optional[List[Molecule]]: """Read all files (.xyz, .pdb, .mol, .txt or further subfolders) within a folder.""" try: mol_type = 'input_cores' if mol_dict.is_core else 'input_ligands' _file_list = os.listdir(mol_dict.mol) optional_dict = Settings( {k: v for k, v in mol_dict.items() if k not in ('mol', 'path')}) file_list = [{i: optional_dict} for i in _file_list] validate_mol(file_list, mol_type, mol_dict.path) return read_mol(file_list) except Exception as ex: print_exception('read_mol_folder', mol_dict.name, ex)
def read_mol_txt(mol_dict: Settings) -> Optional[List[Molecule]]: """Read a plain text file containing one or more SMILES strings.""" try: row = 0 if 'row' not in mol_dict else mol_dict.row column = 0 if 'column' not in mol_dict else mol_dict.column mol_type = 'input_cores' if mol_dict.is_core else 'input_ligands' with open(mol_dict.mol, 'r') as f: iterator = itertools.islice(f, row, None) _file_list = [ i.rstrip('\n').split()[column] for i in iterator if i ] optional_dict = Settings( {k: v for k, v in mol_dict.items() if k not in ('mol', 'path')}) file_list = [{i: optional_dict} for i in _file_list] validate_mol(file_list, mol_type, mol_dict.path) return read_mol(file_list) except Exception as ex: print_exception('read_mol_txt', mol_dict.name, ex)