def string_array_to_molecule(parser_fun, file_name, mol=None): """ Convert a Numpy string array like: [['C', '-1.487460', '-0.028670', '-0.000060'], ['O', '0.376340', '0.028670', '-0.000060'], ['H', '-1.818910', '-1.067060', '-0.000060'], ['H', '-1.866470', '0.473700', '0.889930'], ['H', '-1.866470', '0.473700', '-0.890040'], ['H', '0.756720', '-0.950010', '-0.000060']] To a plams ``Molecule``. """ string_array_to_float = np.vectorize(float) mols = parse_file(parser_fun, file_name).asList() last_mol = np.array(mols[-1]) elems = last_mol[:, 0] coords = string_array_to_float(last_mol[:, 1:]) if mol: if len(coords) == len(mol): plams_mol = mol for i in range(len(plams_mol)): plams_mol.atoms[i].coords = tuple( [float(c) for c in coords[i]]) else: raise RuntimeError("Output molecule does not match input molecule") else: plams_mol = Molecule() for e, c in zip(elems, coords): plams_mol.add_atom(Atom(symbol=e, coords=tuple(c))) return plams_mol
def tuplesXYZ_to_plams(xs): """ Transform a list of namedTuples to a Plams molecule """ plams_mol = Molecule() for at in xs: symb = at.symbol cs = at.xyz plams_mol.add_atom(Atom(symbol=symb, coords=tuple(cs))) return plams_mol
def parse_molecule_traj(file_traj): """ Read Molecules from the job_name.traj file. """ mols = manyXYZ(file_traj) # Last geometry corresponds to the optimized structure opt_mol = mols[-1] plams_mol = Molecule() for at in opt_mol: symb = at.symbol cs = at.xyz plams_mol.add_atom(Atom(symbol=symb, coords=tuple(cs))) return plams_mol
def adf_fragmentsjob(settings, mol, *frozen_frags): mol_tot = Molecule() frag_settings = Settings() for i, frag in enumerate(frozen_frags): frag_id = "frag" + str(i + 1) for m in frag.mol_list: for a in m: a.fragment = frag_id mol_tot += m path = frag.result.kf.path + " type=FDE" frag_settings.specific.adf.fragments[frag_id] = path frag_settings.specific.adf.fde.PW91k = "" mol_tot += mol return adf(settings.overlay(frag_settings), mol_tot, job_name="fde")
def from_rdmol(rdkit_mol): """ Translate an RDKit molecule into a PLAMS molecule type """ plams_mol = Molecule() total_charge = 0 Chem.Kekulize(rdkit_mol) conf = rdkit_mol.GetConformer() for atom in rdkit_mol.GetAtoms(): pos = conf.GetAtomPosition(atom.GetIdx()) ch = atom.GetFormalCharge() plams_mol.add_atom( Atom(atom.GetAtomicNum(), coords=(pos.x, pos.y, pos.z), charge=ch)) total_charge += ch for bond in rdkit_mol.GetBonds(): at1 = plams_mol.atoms[bond.GetBeginAtomIdx()] at2 = plams_mol.atoms[bond.GetEndAtomIdx()] plams_mol.add_bond(Bond(at1, at2, bond.GetBondTypeAsDouble())) plams_mol.charge = total_charge for propname in rdkit_mol.GetPropNames(): plams_mol.properties[propname] = rdkit_mol.GetProp(propname) return plams_mol