Answers.Body: <p>You can use Python &quot;normally&quot; and import the <code>pymol</code> module. In the script that holds the proteins in your matrix, you can add a function that does the super alignment.</p>
  <p>To use it, in your console type <code>pymol -cq this_script_name.py</code>.</p>
  <p>You need to have pymol installed and accessed via console. Easiest way I found to manage it is to create a new environment via conda and install pymol there.</p>
  <pre><code>import pymol
  
  
  def super_prots(prot_1, prot_2):
      pymol.cmd.fetch(prot_1, 'prot_1')
      pymol.cmd.fetch(prot_2, 'prot_2')
  
      # If you are using already downloaded pdb files, use load instead:
      # pymol.cmd.load(prot_1, 'prot_1')
      # pymol.cmd.load(prot_2, 'prot_2')
  
      pymol.cmd.hide('all')
      pymol.cmd.set('ray_opaque_background', 0)
  
      # Show cartoon and paint them different
      pymol.cmd.show('cartoon', 'prot_1')
      pymol.cmd.color('orange', 'prot_1')
      pymol.cmd.show('cartoon', 'prot_2')
      pymol.cmd.color('lightblue', 'prot_2')
  
      # Align both proteins
      pymol.cmd.super('prot_1', 'prot_2')
  
      # Improve image quality, and get png.
      pymol.cmd.set('depth_cue', 0)
      pymol.cmd.set('spec_reflect', 0)
      pymol.cmd.set('cartoon_sampling', 15)
      pymol.cmd.set('ribbon_sampling', 15)
      pymol.cmd.set('antialias', 2)
      pymol.cmd.space('cmyk')
  
      # This creates high-quality images, but might take a long time to
      # process. Adjust parameters accordingly.
      pymol.cmd.png(f'{prot_1}_{prot_2}.png',
                    width=2000,
                    dpi=300,
                    ray=1
                    )
      pymol.cmd.reinitialize()
  
  if __name__ == '__main__':
      # These are entries from PDB. It can work with already downloaded
      # files, but you have to change the function accordingly
      protein_matrix = [['1EWL', '4W5B'],
                        ['4E2D', '3ATZ'],
                        ]
      for prot_1, prot_2 in protein_matrix:
          super_prots(prot_1, prot_2)
  </code></pre>
  <p>This will generate .png images of the alignment, but you can also ask it to save the alignment into .pdb files adding <code>pymol.cmd.save(f'{prot_1}_{prot_2}.pdb')</code></p>
  <p>The commands' documentation can be found <a href="https://pymol.org/pymol-command-ref.html" rel="nofollow noreferrer">here</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-02T10:04:42.003Z
Answers.LastActivityDate: 2022-09-02T10:04:42.003Z
Answers.UserDisplayName: albertr
Body: <p>Is there a way write a script in python to use &quot;super&quot; to align proteins from a 2D array? Each row of the array has 2 columns, and for each row, I want to &quot;super&quot; the two proteins (one in each column)</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-26T02:08:02.973Z
Comments.Text: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Comments.UserDisplayName: Community
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-27T09:41:58.990Z
Comments.Text: What do you mean by super? Is it [this](https://docs.python.org/3.8/library/functions.html#super)?
Comments.UserDisplayName: gringer
Tags: <proteins><phylogenetics><pymol>
Title: PyMol alignment script
ThreadText: # PyMol alignment script
  
  (Asked by: username_0 on 2022-08-26)
  
  Is there a way write a script in python to use "super" to align proteins from a 2D array? Each row of the array has 2 columns, and for each row, I want to "super" the two proteins (one in each column)
  
  **Tags:** proteins, phylogenetics, pymol
  
  > **Comments:**
  > **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
  > **username_2**: What do you mean by super? Is it [this](https://docs.python.org/3.8/library/functions.html#super)?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2022-09-02. Score: 1
  
  You can use Python "normally" and import the `pymol` module. In the script that holds the proteins in your matrix, you can add a function that does the super alignment.
  
  To use it, in your console type `pymol -cq this_script_name.py`.
  
  You need to have pymol installed and accessed via console. Easiest way I found to manage it is to create a new environment via conda and install pymol there.
  
  ```
  import pymol
  
  def super_prots(prot_1, prot_2):
      pymol.cmd.fetch(prot_1, 'prot_1')
      pymol.cmd.fetch(prot_2, 'prot_2')
  
      # If you are using already downloaded pdb files, use load instead:
      # pymol.cmd.load(prot_1, 'prot_1')
      # pymol.cmd.load(prot_2, 'prot_2')
  
      pymol.cmd.hide('all')
      pymol.cmd.set('ray_opaque_background', 0)
  
      # Show cartoon and paint them different
      pymol.cmd.show('cartoon', 'prot_1')
      pymol.cmd.color('orange', 'prot_1')
      pymol.cmd.show('cartoon', 'prot_2')
      pymol.cmd.color('lightblue', 'prot_2')
  
      # Align both proteins
      pymol.cmd.super('prot_1', 'prot_2')
  
      # Improve image quality, and get png.
      pymol.cmd.set('depth_cue', 0)
      pymol.cmd.set('spec_reflect', 0)
      pymol.cmd.set('cartoon_sampling', 15)
      pymol.cmd.set('ribbon_sampling', 15)
      pymol.cmd.set('antialias', 2)
      pymol.cmd.space('cmyk')
  
      # This creates high-quality images, but might take a long time to
      # process. Adjust parameters accordingly.
      pymol.cmd.png(f'{prot_1}_{prot_2}.png',
                    width=2000,
                    dpi=300,
                    ray=1
                    )
      pymol.cmd.reinitialize()
  
  if __name__ == '__main__':
      # These are entries from PDB. It can work with already downloaded
      # files, but you have to change the function accordingly
      protein_matrix = [['1EWL', '4W5B'],
                        ['4E2D', '3ATZ'],
                        ]
      for prot_1, prot_2 in protein_matrix:
          super_prots(prot_1, prot_2)
  
  ```
  
  This will generate .png images of the alignment, but you can also ask it to save the alignment into .pdb files adding `pymol.cmd.save(f'{prot_1}_{prot_2}.pdb')`
  
  The commands' documentation can be found [here](https://pymol.org/pymol-command-ref.html).
  
  
  ---
  
  