How to import multiple pdb files in a file in local computer to pymol simultaneously
1
0
Entering edit mode
4.8 years ago
anndybud • 0

Hi all, I am trying to import my pdb files from different files in a file in local computer to pymol software, and then to align all these pdb. I just downloaded a script (load_files) online from pymol wiki, but I don't know how to modify it to enable the import. Could you give me any suggestions? Thank you very much!

The script is as follows:

# Copyright (c) 2004 Robert L. Campbell
from pymol import cmd
import glob

def load_files(files):
  """
  load_files <files>

  loads multiple files (using filename globbing)
  into a multiple objects named as the files are (e.g. collection of
  downloaded PDB files).

  e.g. load_files prot_*.pdb
  """
  file_list = glob.glob(files)
  if file_list:
    file_list.sort()
    for i in file_list:
      #obj_name = i.replace('.pdb','')
      #cmd.load(file_list[i],obj_name)
      cmd.load(i)
  else:
    print("No files found for pattern %s" % files)

cmd.extend('load_files',load_files)

Bests,

Yaohui

software error • 3.5k views
ADD COMMENT
4
Entering edit mode
4.8 years ago
Mensur Dlakic ★ 27k

You do not need to modify anything. Let's say that your script is saved in directory /home/anddy and your pdb files in /home/anddy/PDB. After opening Pymol GUI, click next to the PyMOL> where the blinking cursor is and you will enter command line. Type:

run /home/anddy/load_files.py

This will load the script and give you new command called load_files. Now type:

load_files /home/anddy/PDB/*.pdb

and that will load all the *.pdb files from that particular directory.

ADD COMMENT
0
Entering edit mode

Hi Dlakic, Thank you very much! That works! So here comes another question: now I am trying to align all these pdb files to one of the pdb, let's say proteinA. So I typed in the following command lines: align all(target=proteinA,mobile_selection='name ca',target_selection='name ca',cutoff=2, cycles=5,cgo_object=0,method='align'). But it didn't work, and gave me a warning: Parsing-Error: missing required argument in function align : target. How shall I revise these commands? Thank you very much for help! The script used here is as follows:

#! /usr/bin/env python
# original Written by Jules Jacobsen (jacobsen@ebi.ac.uk). Feel free to do whatever you like with this code.
# extensively modified by Robert L. Campbell (rlc1@queensu.ca)

from __future__ import print_function
from pymol import cmd

def align_all(target=None,mobile_selection='name ca',target_selection='name ca',cutoff=2, cycles=5,cgo_object=0,method='align'):
  """
  Aligns all models in a list to one target

  usage:
    align_all [target][target_selection=name ca][mobile_selection=name ca]
    [cutoff=2][cycles=5][cgo_object=0][method='align']

        where method can be align, super or cealign

        where target specifies the model id you want to align all others against,
        and target_selection, mobile_selection, cutoff and cycles are options
        passed to the align or super command.

    Options for method='align' or method='super':

      By default the selection is all C-alpha atoms and the cutoff is 2 and the
      number of cycles is 5.
      Setting cgo_object to 1, will cause the generation of an alignment object for
      each object.  They will be named like <object>_on_<target>, where <object> and
      <target> will be replaced by the real object and target names.

    Example:
      align_all target=name1, mobile_selection=c. b & n. n+ca+c+o,target_selection=c. a & n. n+ca+c+o

  """
  cutoff = int(cutoff)
  cycles = int(cycles)
  cgo_object = int(cgo_object)

  object_list = cmd.get_names()
  object_list.remove(target)

  rmsd = {}
  rmsd_list = []
  for i in range(len(object_list)):
    if cgo_object:
      objectname = 'align_%s_on_%s' % (object_list[i],target)
      if method == 'align':
        rms = cmd.align('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles,object=objectname)
      elif method == 'super':
        rms = cmd.super('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles,object=objectname)
      elif method == 'cealign':
        rmsdict = cmd.cealign('%s & %s' % (target,target_selection),'%s & %s' % (object_list[i],mobile_selection))
        rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0,0]
      else:
        print("only 'align', 'super' and 'cealign' are accepted as methods")
        sys.exit(-1)
    else:
      if method == 'align':
        rms = cmd.align('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)
      elif method == 'super':
        rms = cmd.super('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)
      elif method == 'cealign':
        rmsdict = cmd.cealign('%s & %s' % (target,target_selection),'%s & %s' % (object_list[i],mobile_selection))
        rms = [rmsdict['RMSD'],rmsdict['alignment_length'],1,0,0]
      else:
        print("only 'align', 'super' and 'cealign' are accepted as methods")
        sys.exit(-1)

    rmsd[object_list[i]] = (rms[0],rms[1])
    rmsd_list.append((object_list[i],rms[0],rms[1]))

  rmsd_list_sorted = sorted(rmsd_list,key=lambda x: x[1])
# loop over dictionary and print out matrix of final rms values
  print("Aligning against:",target)
  for object_name in object_list:
    print("%s: %6.3f using %d atoms" % (object_name,rmsd[object_name][0],rmsd[object_name][1]))

  print("\nSorted from best match to worst:")
  for r in rmsd_list_sorted:
    print("%s: %6.3f using %d atoms" % r)

cmd.extend('align_all',align_all)
ADD REPLY
0
Entering edit mode

I think it would be more useful if you provide a link to the script rather than trying to paste the contents. It may be a good idea to delete the second posting of the same message as it clutters this page.

You are trying to mimic the formatting of the def line from that script, while the proper way to do it is without parentheses, as demonstrated in the script itself on the Example: line:

align_all target=proteinA, mobile_selection=(name ca), target_selection=(name ca), cutoff=2, cycles=5, cgo_object=0, method=align

I am assuming that the use of parentheses was your mistake, but it could also be that you mis-typed the name of your target (proteinA) since that is what error message indicates. Also, the exact selection formatting in PyMol can be difficult to understand, and I suggest you read about it here and here.

On a different note: PyMol does not have the greatest algorithm for structural alignment. Unless your proteins are very similar structurally, I would consider aligning them externally and loading the aligned structures into PyMol. Some links for that in case you don't have a stand-alone aligner available:

https://zhanglab.ccmb.med.umich.edu/TM-align/

http://pwp.gatech.edu/cssb/fr-tm-align/

http://matt.cs.tufts.edu/

https://theobald.brandeis.edu/theseus/

Finally, if this is helpful to you, you should consider upvoting my answer(s) and marking it as accepted.

ADD REPLY
0
Entering edit mode

Hi Dlakic, Thank you very much! Your suggestion again works! I think I have already upvoted your answer and also accepted it. If there is anything wrong, just tell me. Thank you very much again!

ADD REPLY

Login before adding your answer.

Traffic: 3741 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6