def __call__(self, atoms1, atoms2): args = dict(use_charge=self.use_charge, adjacency=self.adjacency) g1 = Graph.from_ase(atoms1, **args) g2 = Graph.from_ase(atoms2, **args) R1 = self._mlgk(g1, g1).diagonal()**-0.5 R2 = self._mlgk(g2, g2).diagonal()**-0.5 R12 = self._mlgk(g1, g2) K = R1[:, None] * R12 * R2[None, :] D = np.sqrt(np.maximum(2 - 2 * K, 0)) return max(D.min(axis=1).max(), D.min(axis=0).max())
def test_molecular_kernel_on_organics(benchmark): graphs = [ Graph.from_ase(molecule(name)) for name in g2.names if len(molecule(name)) > 1 ] kernel = Tang2019MolecularKernel() def fun(kernel, graphs): return kernel(graphs, nodal=True) benchmark.pedantic(fun, args=(kernel, graphs), iterations=3, rounds=3, warmup_rounds=1)
def test_ase(atoms): g = Graph.from_ase(atoms) assert(len(g.nodes) == len(atoms)) assert(len(g.edges) > 0)
def test_ase_pbc2(atoms): adj = AtomicAdjacency(shape='tent1', length_scale=1.0, zoom=1) graph_pbc = Graph.from_ase(atoms, use_pbc=True, adjacency=adj) graph_nopbc = Graph.from_ase(atoms, use_pbc=False, adjacency=adj) assert(len(graph_pbc.edges) > len(graph_nopbc.edges))
def test_ase_pbc1(atoms, adj): graph_pbc = Graph.from_ase(atoms, use_pbc=True, adjacency=adj) graph_nopbc = Graph.from_ase(atoms, use_pbc=False, adjacency=adj) assert(len(graph_pbc.edges) == len(graph_nopbc.edges))
def test_ase_one(): atoms = molecule('H2') graph = Graph.from_ase(atoms) assert(len(graph.nodes) == 2) assert(len(graph.edges) == 1)
sys.stderr.write('Unrecognized argument: %s\n' % arg) sys.exit(1) print(arg_dict) formula = arg_dict.pop('formula', 'CH3COOH') zoom = arg_dict.pop('zoom', 1.5) repeat = arg_dict.pop('repeat', 4) nlaunch = arg_dict.pop('nlaunch', 1) block_per_sm = arg_dict.pop('block_per_sm', 8) block_size = arg_dict.pop('block_size', 128) device = pycuda.driver.Device(arg_dict.pop('device', 0)) njobs = device.MULTIPROCESSOR_COUNT * block_per_sm * repeat g = Graph.from_ase(molecule(formula), adjacency=dict(h=zoom)) kernel = Kernel() ''' generate jobs ''' jobs = [Job(0, 0, GPUArray(len(g.nodes)**2, np.float32)) for i in range(njobs)] ''' call GPU kernel ''' for i in range(nlaunch): kernel.kernel._launch_kernel([g], jobs, nodal=False, lmin=0) R = jobs[0].vr_gpu.get().reshape(len(g.nodes), -1) r = R.sum() print('Nodal similarity:\n', R, sep='') print('Overall similarity:\n', r, sep='') for job in jobs:
file = arg_dict.pop('file', 'pdb-3kDa-1324.json') active = json.loads('[' + arg_dict.pop('active', 1) + ']') zoom = arg_dict.pop('zoom', 1.5) # reorder = arg_dict['reorder'] if 'reorder' in arg_dict else 'natural' sys.stderr.write('Loading file %s\n' % file) try: pdb_json = json.loads(open(file).read()) except FileNotFoundError: pdb_json = json.loads( open(os.path.join(os.path.dirname(__file__), file)).read() ) graph_list = [] for i in active: mol = pdb_json[i] sys.stderr.write( '%5d: %s, %d atoms\n' % (i, mol['pdb_id'], len(mol['sym'])) ) atoms = Atoms(mol['sym'], mol['xyz']) graph_list.append(Graph.from_ase(atoms, adjacency=dict(h=zoom))) kernel = Tang2019MolecularKernel() print(kernel(graph_list))
def test_ase_pbc2(atoms): graph_pbc = Graph.from_ase(atoms, use_pbc=True, adjacency=simple_adj) graph_nopbc = Graph.from_ase(atoms, use_pbc=False, adjacency=simple_adj) assert (len(graph_pbc.edges) > len(graph_nopbc.edges))
def fun(atoms): return Graph.from_ase(atoms)