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)
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)
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
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