當前位置: 首頁>>代碼示例>>Python>>正文


Python mdtraj.load方法代碼示例

本文整理匯總了Python中mdtraj.load方法的典型用法代碼示例。如果您正苦於以下問題:Python mdtraj.load方法的具體用法?Python mdtraj.load怎麽用?Python mdtraj.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mdtraj的用法示例。


在下文中一共展示了mdtraj.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: func

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def func(args, parser):
    # delay import of the rest of the module to improve `mdentropy -h` performance
    import pickle
    import mdtraj as md
    import pandas as pd
    from ..utils import parse_files
    from ..metrics import DihedralMutualInformation

    files = parse_files(args.traj)
    traj = md.load(files, top=args.top, stride=args.stride)

    mi = DihedralMutualInformation(n_bins=args.nbins, types=args.types,
                                   method=args.method, threads=args.n_threads,
                                   normed=True)

    M = mi.partial_transform(traj, shuffle=iter, verbose=True)

    df = pd.DataFrame(M, columns=mi.labels)

    pickle.dump(df, open(args.out, 'wb')) 
開發者ID:msmbuilder,項目名稱:mdentropy,代碼行數:22,代碼來源:dmutinf.py

示例2: func

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def func(args, parser):
    # delay import of the rest of the module to improve `mdentropy -h`
    # performance
    import pickle
    import mdtraj as md
    import pandas as pd
    from ..utils import parse_files
    from ..metrics import DihedralTransferEntropy

    f1, f2 = parse_files(args.current), parse_files(args.past)

    current = md.load(f1, top=args.top, stride=args.stride)
    past = md.load(f2, top=args.top, stride=args.stride)

    tent = DihedralTransferEntropy(n_bins=args.nbins, types=args.types,
                                   method=args.method, threads=args.n_threads,
                                   normed=True)

    T = tent.partial_transform((past, current), shuffle=iter, verbose=True)

    df = pd.DataFrame(T, columns=tent.labels)

    pickle.dump(df, open(args.out, 'wb')) 
開發者ID:msmbuilder,項目名稱:mdentropy,代碼行數:25,代碼來源:dtent.py

示例3: test_convex_find_pockets

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def test_convex_find_pockets(self):
    """Test that some pockets are filtered out."""
    current_dir = os.path.dirname(os.path.realpath(__file__))
    protein_file = os.path.join(current_dir, "1jld_protein.pdb")
    ligand_file = os.path.join(current_dir, "1jld_ligand.sdf")

    import mdtraj as md
    protein = md.load(protein_file)

    finder = dc.dock.ConvexHullPocketFinder()
    all_pockets = finder.find_all_pockets(protein_file)
    pockets = finder.find_pockets(protein_file)
    # Test that every atom in pocket maps exists
    n_protein_atoms = protein.xyz.shape[1]
    for pocket in pockets:
      assert isinstance(pocket, box_utils.CoordinateBox)

    assert len(pockets) < len(all_pockets) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:20,代碼來源:test_binding_pocket.py

示例4: visualize_complex

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def visualize_complex(complex_mdtraj):
  ligand_atoms = [a.index for a in complex_mdtraj.topology.atoms if "LIG" in str(a.residue)]
  binding_pocket_atoms = md.compute_neighbors(complex_mdtraj, 0.5, ligand_atoms)[0]
  binding_pocket_residues = list(set([complex_mdtraj.topology.atom(a).residue.resSeq for a in binding_pocket_atoms]))
  binding_pocket_residues = [str(r) for r in binding_pocket_residues]
  binding_pocket_residues = " or ".join(binding_pocket_residues)

  traj = nglview.MDTrajTrajectory( complex_mdtraj ) # load file from RCSB PDB
  ngltraj = nglview.NGLWidget( traj )
  ngltraj.representations = [
  { "type": "cartoon", "params": {
  "sele": "protein", "color": "residueindex"
  } },
  { "type": "licorice", "params": {
  "sele": "(not hydrogen) and (%s)" %  binding_pocket_residues
  } },
  { "type": "ball+stick", "params": {
  "sele": "LIG"
  } }
  ]
  return ngltraj 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:23,代碼來源:utils.py

示例5: prepare_example

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def prepare_example():
    """
    Prepare the host-guest example relative calculation.
    """
    #load in the host and guest molecules
    host_traj = extract_molecule(host_guest_path, "HST")
    guest_traj = extract_molecule(host_guest_path, "GST")

    #convert the trajs to mols
    host_mol = convert_mdtraj_to_oemol(host_traj)
    guest_mol = convert_mdtraj_to_oemol(guest_traj)

    #make the other guest molecule:
    new_guest_molecule = iupac_to_oemol(alternate_guest)

    #write out the host molecule:
    write_host(host_mol, host_vacuum_path)

    #write out the guest molecules:
    write_guest_molecules(guest_mol, new_guest_molecule, guests_vacuum_path) 
開發者ID:choderalab,項目名稱:perses,代碼行數:22,代碼來源:prepare_host_guest.py

示例6: _initialise_frame

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def _initialise_frame(self, frame):
        """
        Parse a GROMACS GRO file and create Residues/Atoms
        Required before reading coordinates from XTC file

        :param frame: Frame instance to initialise from GRO file
        """
        import mdtraj
        top = mdtraj.load(self._topname)

        frame.name = ""
        self.num_atoms = top.n_atoms
        frame.natoms = top.n_atoms

        frame.residues = [Residue(name=res.name, num=res.resSeq) for res in top.topology.residues]

        for atom in top.topology.atoms:
            new_atom = Atom(name=atom.name, num=atom.serial,
                            coords=top.xyz[0][atom.index])
            frame.residues[atom.residue.index].add_atom(new_atom)

        frame.box = top.unitcell_lengths[0] 
開發者ID:jag1g13,項目名稱:pycgtool,代碼行數:24,代碼來源:framereader.py

示例7: _load_to_position

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def _load_to_position(spec, arr_shape):
    '''
    Load a specified file into a specified position by spec. The
    arr_shape parameter lets us know how big the final array should be.
    '''
    (position, filename, load_kwargs) = spec

    xyz = md.load(filename, **load_kwargs).xyz

    # mp.Array must be converted to numpy array and reshaped
    arr = _tonumpyarray(shared_array).reshape(arr_shape)

    # dump coordinates in.
    arr[position:position+len(xyz)] = xyz

    return xyz.shape 
開發者ID:bowman-lab,項目名稱:enspara,代碼行數:18,代碼來源:load.py

示例8: test_assign_to_nearest_center_few_centers

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def test_assign_to_nearest_center_few_centers():

    # assign_to_nearest_center takes two code paths, one for
    # n_centers > n_frames and one for n_frames > n_centers. This tests
    # the latter.
    trj = md.load(get_fn('frame0.xtc'), top=get_fn('native.pdb'))
    center_frames = [0, int(len(trj)/3), int(len(trj)/2)]

    assigns, distances = util.assign_to_nearest_center(
        trj, trj[center_frames], md.rmsd)

    alldists = np.zeros((len(center_frames), len(trj)))
    for i, center_frame in enumerate(trj[center_frames]):
        alldists[i] = md.rmsd(trj, center_frame)

    assert_allclose(np.min(alldists, axis=0), distances, atol=1e-3)
    assert_array_equal(np.argmin(alldists, axis=0), assigns) 
開發者ID:bowman-lab,項目名稱:enspara,代碼行數:19,代碼來源:test_cluster_util.py

示例9: test_reassign_script

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def test_reassign_script():

    topologies = [get_fn('native.pdb'), get_fn('native.pdb')]
    trajectories = [get_fn('frame0.xtc'), get_fn('frame0.xtc')]

    centers = [c for c in md.load(trajectories[0], top=topologies[0])[::50]]

    with tempfile.NamedTemporaryFile(suffix='.pkl') as ctrs_f:
        pickle.dump(centers, ctrs_f)
        ctrs_f.flush()

        runhelper(
            ['--centers', ctrs_f.name,
             '--trajectories', trajectories[0], trajectories[1],
             '--atoms', '(name N or name C or name CA or name H or name O)',
             '--topology', topologies]) 
開發者ID:bowman-lab,項目名稱:enspara,代碼行數:18,代碼來源:test_apps_reassign.py

示例10: test_load_as_concatenated_stride

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def test_load_as_concatenated_stride(self):

        t1 = md.load(self.trj_fname, top=self.top)
        t2 = md.load(self.trj_fname, top=self.top)
        t3 = md.load(self.trj_fname, top=self.top)

        print(len(t1))
        print(len(md.load(self.trj_fname, top=self.top, stride=10)))

        lengths, xyz = load_as_concatenated(
            [self.trj_fname]*3,
            top=self.top,
            stride=10,
            processes=2)

        expected = np.concatenate([t1.xyz[::10],
                                   t2.xyz[::10],
                                   t3.xyz[::10]])

        self.assertTrue(np.all(expected == xyz))
        self.assertEqual(expected.shape, xyz.shape) 
開發者ID:bowman-lab,項目名稱:enspara,代碼行數:23,代碼來源:test_ra.py

示例11: test_selection_load_as_concatenated

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def test_selection_load_as_concatenated(self):
        '''
        **kwargs should work with load_as_concatenated

        Verify that when *kwargs is used in load_as_concatenated, it is
        applied to each trajectory as it's loaded (e.g. for the purposes
        of selection).
        '''

        selection = np.array([1, 3, 6])

        t1 = md.load(self.trj_fname, top=self.top, atom_indices=selection)
        t2 = md.load(self.trj_fname, top=self.top, atom_indices=selection)
        t3 = md.load(self.trj_fname, top=self.top, atom_indices=selection)

        lengths, xyz = load_as_concatenated(
            [self.trj_fname]*3,
            top=self.top,
            atom_indices=selection,
            processes=3)
        expected = np.concatenate([t1.xyz, t2.xyz, t3.xyz])

        self.assertTrue(np.all(expected == xyz))
        self.assertEqual(expected.shape, xyz.shape) 
開發者ID:bowman-lab,項目名稱:enspara,代碼行數:26,代碼來源:test_ra.py

示例12: load_trajs

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def load_trajs(args):
    """ Creates a generator object that can be then passed to the CARDS framework.
    """
    trajectories = args.trajectories[0]
    topology = args.topology[0]
    #filenames = glob(trajectories)
    targets = {os.path.basename(topf): "%s files" % len(trjfs) for topf, trjfs
               in zip(args.topology, args.trajectories)}
    logger.info("Starting CARDS; targets:\n%s",
                json.dumps(targets, indent=4))

    #gen = (md.load(traj, top=topology) for traj in args.trajectories)
    gen = load_trajectory_generator(trajectories, topology)

    logger.info("Created generator")

    return gen 
開發者ID:bowman-lab,項目名稱:enspara,代碼行數:19,代碼來源:collect_cards.py

示例13: read_xtc

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def read_xtc(trajfile, top, **kwargs):
    """ read the trajectrory using mdtraj module from the xtc file """

    print("Read trajectory file: ", trajfile)
    print("Read topology from:   ", top)

    t1 = time.time()
    trajectory = md.load(trajfile, top=top)
    t2 = time.time() - t1

    nframes, natoms = trajectory.xyz.shape[:2]
    print("# frames: ", nframes)
    print("# atoms:  ", natoms)
    print("Read trajecory in %.0f s\n" % t2)

    return trajectory 
開發者ID:gVallverdu,項目名稱:myScripts,代碼行數:18,代碼來源:hbonds.py

示例14: featurize

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def featurize(self, protein_file, pockets):
    """
    Calculate atomic coodinates.

    Params
    ------
    protein_file: str
      Location of PDB file. Will be loaded by MDTraj
    pockets: list[CoordinateBox]
      List of `dc.utils.CoordinateBox` objects.

    Returns
    -------
    A numpy array of shale `(len(pockets), n_residues)`
    """
    import mdtraj
    protein_coords = rdkit_util.load_molecule(
        protein_file, add_hydrogens=False, calc_charges=False)[0]
    mapping = boxes_to_atoms(protein_coords, pockets)
    protein = mdtraj.load(protein_file)
    n_pockets = len(pockets)
    n_residues = len(BindingPocketFeaturizer.residues)
    res_map = dict(zip(BindingPocketFeaturizer.residues, range(n_residues)))
    all_features = np.zeros((n_pockets, n_residues))
    for pocket_num, pocket in enumerate(pockets):
      pocket_atoms = mapping[pocket]
      for ind, atom in enumerate(pocket_atoms):
        atom_name = str(protein.top.atom(atom))
        # atom_name is of format RESX-ATOMTYPE
        # where X is a 1 to 4 digit number
        residue = atom_name[:3]
        if residue not in res_map:
          logger.info("Warning: Non-standard residue in PDB file")
          continue
        atomtype = atom_name.split("-")[1]
        all_features[pocket_num, res_map[residue]] += 1
    return all_features 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:39,代碼來源:binding_pocket_features.py

示例15: visualize_ligand

# 需要導入模塊: import mdtraj [as 別名]
# 或者: from mdtraj import load [as 別名]
def visualize_ligand(ligand_mdtraj):
  traj = nglview.MDTrajTrajectory( ligand_mdtraj ) # load file from RCSB PDB
  ngltraj = nglview.NGLWidget( traj )
  ngltraj.representations = [
    { "type": "ball+stick", "params": {"sele": "all" } } ]
  return ngltraj 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:8,代碼來源:utils.py


注:本文中的mdtraj.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。