示例#1
0
def parse_molecule_traj(file_traj):
    """
    Read Molecules from the *.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
示例#2
0
def rdkit2plams(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
示例#3
0
def string_array_to_molecule(parser_fun, file_name):
    """
    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:])
    plams_mol = Molecule()
    for e, c in zip(elems, coords):
        plams_mol.add_atom(Atom(symbol=e, coords=tuple(c)))

    return plams_mol