Beispiel #1
0
def a2md_from_mol(mol: Mol2):
    """
    returns the density model associated to a Mol2
    :param mol:
    :type mol: Mol2
    :return:
    :rtype: Molecule
    """
    an = mol.get_atomic_numbers()
    coords = mol.get_coordinates(units="au")
    charge = mol.get_absolute_charges()
    topology = mol.get_bonds()
    segments = mol.segment_idx
    topo_array = []
    for i in range(mol.get_number_atoms()):
        topo_array.append([])
    for i in range(mol.get_number_bonds()):
        begin = int(topology[i, 0])
        end = int(topology[i, 1])
        topo_array[begin - 1].append(end - 1)
        topo_array[end - 1].append(begin - 1)
    return Molecule(coordinates=coords,
                    atomic_numbers=an,
                    charge=charge,
                    topology=topo_array,
                    segments=segments)
Beispiel #2
0
def rename_atoms(mol: Mol2, new_names: Dict):
    n = mol.get_number_atoms()
    if len(new_names['_ATOMS']) != n:
        raise RuntimeError("number of atoms does not match")
    new_anames = [i[0] for i in new_names['_ATOMS']]
    new_segmentsidx = [i[1] for i in new_names['_ATOMS']]
    new_segments = [new_names['_SEGMENTS'][i[1]] for i in new_names['_ATOMS']]
    mol.atom_names = new_anames
    mol.segments = new_segments
    mol.segment_idx = new_segmentsidx
    return mol
Beispiel #3
0
def split_space(mm: Mol2, fun: Callable):
    """
    split space
    ---
    divides fun in n functions centered around atoms
    :param mm:
    :param fun:
    :return:
    """
    r = mm.get_coordinates(units='au')
    n = mm.get_number_atoms()
    for i in range(n):
        r0 = r[i, :]
        yield lambda x: fun(x + r0) * (voronoi(x + r0, r) == i)
Beispiel #4
0
def integrate_density_functional_gradient(functional: Callable,
                                          mol: Mol2,
                                          nfuns: int,
                                          grid='coarse',
                                          res=100):
    r = mol.get_coordinates(units='au')
    n = mol.get_number_atoms()
    functional_value = np.zeros(nfuns, dtype='float64')
    for i in range(n):
        r0 = r[i, :]
        fx = lambda x: functional(x + r0) * (voronoi(x + r0, r) == i).reshape(
            -1, 1)
        functional_value += pi_lebedev_m(fx, nfuns, radial_res=res, grid=grid)
    return functional_value
Beispiel #5
0
def convert(mol : Mol2):
    G = nx.Graph()
    for i in range(mol.get_number_atoms()):
        G.add_node(i, **mol.get_atom(i))
    bonds = mol.get_bonds()
    bonds = bonds - 1
    for i in range(mol.get_number_bonds()):
        G.add_edge(bonds[i, 0], bonds[i, 1])

    bonds, angles, dihedrals = decompose_molecule_graph(G)
    dbonds = np.zeros(len(bonds), dtype='float64')
    dangles = np.zeros(len(angles), dtype='float64')
    ddihedrals = np.zeros(len(dihedrals), dtype='float64')

    for i in range(len(bonds)):
        atom1, atom2 = bonds[i].split("|")
        atom1 = int(atom1)
        atom2 = int(atom2)
        x1 = G.nodes[atom1]['coordinates']
        x2 = G.nodes[atom2]['coordinates']
        dbonds[i] = distance(x1, x2)

    for i in range(len(angles)):
        ends, center = angles[i].split(",")
        atom1, atom3 = ends.split("|")
        atom1 = int(atom1)
        atom3 = int(atom3)
        atom2 = int(center)
        x1 = G.nodes[atom1]['coordinates']
        x2 = G.nodes[atom2]['coordinates']
        x3 = G.nodes[atom3]['coordinates']
        dangles[i] = angle(x1, x2, x3)

    for i in range(len(dihedrals)):
        ends, center = dihedrals[i].split(",")
        atom1, atom4 = ends.split("|")
        atom2, atom3 = center.split("|")
        atom1 = int(atom1)
        atom3 = int(atom3)
        atom2 = int(atom2)
        atom4 = int(atom4)
        x1 = G.nodes[atom1]['coordinates']
        x2 = G.nodes[atom2]['coordinates']
        x3 = G.nodes[atom3]['coordinates']
        x4 = G.nodes[atom4]['coordinates']
        ddihedrals[i] = dihedral(x1, x2, x3, x4)

    return dbonds, dangles, ddihedrals
Beispiel #6
0
def genamd_from_mol2(mol: Mol2, device: torch.device, nfuns: int):
    labels = mol.get_symbols()
    centers = torch.tensor(mol.get_coordinates(units='au'),
                           dtype=torch.float,
                           device=device)
    labels = torch.tensor([SYMBOL2NN[i] for i in labels],
                          dtype=torch.long,
                          device=device)
    centers.unsqueeze_(0)
    labels.unsqueeze_(0)
    natoms = mol.get_number_atoms()
    coefficients = torch.ones(1,
                              natoms,
                              nfuns,
                              dtype=torch.float,
                              device=device)
    return labels, centers, coefficients