Answers.Body: <p>well wasnt able to figure out how to make openapigenerator work with rcsb pdb ModelServer <a href="https://models.rcsb.org/" rel="nofollow noreferrer">https://models.rcsb.org/</a>, I ended up with this code
  copying the webserver manual input results for ligands:</p>
  <pre><code>import requests
  
  
  def main():
     
    risposta = requests.get('https://models.rcsb.org/v1/1d17/ligand?encoding=cif&amp;copy_all_categories=false&amp;download=true&amp;filename=out',
                            
                            allow_redirects=True)
    
    open('out.cif', 'wb').write(risposta.content)
  
    print(risposta.status_code)
  
  if __name__ == '__main__':      
     
     main()
  </code></pre>
  <p>unfortunately the server gives you the wrong ligand (try it out)</p>
  <p>it says :' ​/v1​/{id}​/ligand
  Coordinates of the first group satisfying the given criteria.'</p>
  <p>tried with:</p>
  <pre><code>risposta = requests.get('https://models.rcsb.org/v1/1d17/ligand?label_atom_id=NGM&amp;encoding=cif&amp;copy_all_categories=false&amp;download=true&amp;filename=out',
                         
                         allow_redirects=True)
  </code></pre>
  <p>but no luck again, think problem is in downloaded file :</p>
  <pre><code>_model_server_params.name     atom_site 
  _model_server_params.value    '{&quot;label_atom_id&quot;:&quot;NGM&quot;}'  ###### here
  </code></pre>
  <p>but not an expert of APis and openAPI at all</p>
  <p>EDITED:</p>
  <p>eventually I got it right using in the code above:</p>
  <pre><code>risposta = requests.get('https://models.rcsb.org/v1/1d17/ligand?label_comp_id=NGM&amp;encoding=cif&amp;copy_all_categories=false&amp;download=true&amp;filename=out',
                        
                        allow_redirects=True) 
  </code></pre>
  <p>so I get a out.cif file containing NGM</p>
  <p>using another database and FTP :</p>
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  &quot;&quot;&quot;
  Created on Fri Nov 19 19:29:30 2021
  
  @author: Pietro
  
  
  https://bioinformatics.stackexchange.com/questions/18076/help-me-in-understanding-the-pdb-file#comment25289_18076
  
  Ligand extract:
      
  https://stackoverflow.com/questions/61390035/how-to-save-each-ligand-from-a-pdb-file-separately-with-bio-pdb
  
  &quot;&quot;&quot;
  
  from ftplib import FTP
  
  import gzip
  
  import os
  
  from Bio.PDB import PDBParser, PDBIO, Select
  
  
  def is_het(residue):
      res = residue.id[0]
      return res != &quot; &quot; and res != &quot;W&quot;
  
  
  class ResidueSelect(Select):
      def __init__(self, chain, residue):
          self.chain = chain
          self.residue = residue
  
      def accept_chain(self, chain):
          return chain.id == self.chain.id
  
      def accept_residue(self, residue):
          &quot;&quot;&quot; Recognition of heteroatoms - Remove water molecules &quot;&quot;&quot;
          return residue == self.residue and is_het(residue)
  
  
  def extract_ligands(path):
      &quot;&quot;&quot; Extraction of the heteroatoms of .pdb files &quot;&quot;&quot;
  
      for pfb_file in os.listdir(path):
          i = 1
          if pfb_file.endswith('.pdb') and not pfb_file.startswith(&quot;lig_&quot;):
              pdb_code = pfb_file[:-4]
              pdb = PDBParser().get_structure(pdb_code, path + pfb_file)
              io = PDBIO()
              io.set_structure(pdb)
              for model in pdb:
                  for chain in model:
                      for residue in chain:
                          if not is_het(residue):
                              continue
                          print(f&quot;saving {chain} {residue}&quot;)
                          io.save(f&quot;lig_{pdb_code}_{i}.pdb&quot;, ResidueSelect(chain, residue))
                          i += 1
  
  
  
  
  def getFile(ftp, filename):
      try:
          # ftp.retrbinary(&quot;RETR&quot;, filename ,open(code+'.gz', 'wb').write)
          ftp.retrbinary(&quot;RETR &quot; + filename ,open(code+'.gz', 'wb').write)
      except:
          print(&quot;Error somewhere !!!!&quot;)
  
  
  code = '1D17'
  filename = 'pdb'+code.lower()+'.ent.gz'                 ## pdb1D17.ent.gz    
  
  print(filename)
  
  
  
  
  ftp = FTP('ftp.wwpdb.org')   # connect to host, default port
  
  # ftp.login()               # user anonymous, passwd anonymous@
  print(ftp.login())
  
  ftp.cwd('/pub/pdb/data/structures/all/pdb/')  
  
  print(ftp.pwd()  )
  
  getFile(ftp, filename)
  
  zipped = gzip.open(code+'.gz', 'rb')
  
  unzipped = zipped.read()
  
  # print(unzipped)
  
  
  saved = open(code+'.pdb', 'wb')
  
  saved.write(unzipped)
  saved.close()
  
  
  path = './'
  
  extract_ligands(path)
  
  </code></pre>
  <p>copying from : <a href="https://stackoverflow.com/questions/61390035/how-to-save-each-ligand-from-a-pdb-file-separately-with-bio-pdb">https://stackoverflow.com/questions/61390035/how-to-save-each-ligand-from-a-pdb-file-separately-with-bio-pdb</a></p>
  <p>and using FTP from ftplib on <a href="http://ftp.wwpdb.org/pub/pdb/data/structures/all/pdb/" rel="nofollow noreferrer">http://ftp.wwpdb.org/pub/pdb/data/structures/all/pdb/</a>   : PDB - FTP Archive over HTTP</p>
  <p>NOGALAMYCIN is NGM third ligand downloaded (shuold be the only one according to <a href="https://www.rcsb.org/structure/1d17" rel="nofollow noreferrer">https://www.rcsb.org/structure/1d17</a>)</p>
  <p>In any case I am failing at ubderstandung *,-)  how <a href="https://models.rcsb.org/" rel="nofollow noreferrer">https://models.rcsb.org/</a></p>
  <p>Parameters are related to <a href="https://pdb101.rcsb.org/learn/guide-to-understanding-pdb-data/beginner%E2%80%99s-guide-to-pdb-structures-and-the-pdbx-mmcif-format" rel="nofollow noreferrer">https://pdb101.rcsb.org/learn/guide-to-understanding-pdb-data/beginner%E2%80%99s-guide-to-pdb-structures-and-the-pdbx-mmcif-format</a> , the mmcif format</p>
  <p>but as I told before I can't read inside openapi.json OpenAPI Specification</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-22T09:33:36.010Z
Answers.LastActivityDate: 2021-11-22T17:34:06.490Z
Answers.LastEditDate: 2021-11-22T17:34:06.490Z
Answers.UserDisplayName: pippo1980
Body: <p>Can anybody please explain the below line to me.</p>
  <p>&quot;We took the structure and coordinates of nogalamycin
  from the X-ray structure determined in PDB code = 1D17&quot;</p>
  <p>What do I need to download from there....a pdb file or what?</p>
  <p>Thank you</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-19T17:46:58.130Z
Comments.Text: If you want to download the structure – yes, a PDB file or mmCIF file (different file formats with the same structure).
Comments.UserDisplayName: marcin
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-19T17:57:11.513Z
Comments.Text: Thank you so much for your reply. But the pdb file is about the complex molecule(ligand-DNA). The above line says "We took the structure and coordinates of nogalamycin from the X-ray structure determined". The pdb id page shows ligand structure separately. .... download CCD file or instance file. Do you think I need to download only ligand file?
Comments.UserDisplayName: dnalectronics
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-19T21:29:36.450Z
Comments.Text: Ah, I overlooked that you are after the ligand only. Instance coordinates are taken from this structure (ligand extracted from the complex). Ideal coordinates are taken from the CCD (Chemical Component Dictionary) – the same ligand, but it's 3D structure doesn't need to be identical to the ligand in this complex. At least that's how I understand it. Another alternative is to download the PDB file with the whole structure and manually extract the ligand, but that's more cumbersome.
Comments.UserDisplayName: marcin
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-19T21:33:32.150Z
Comments.Text: there is a https://models.rcsb.org/       ModelServer, 
  The ModelServer is a service for accessing subsets of macromolecular model data. I am sure there is a way to get just the ligand. Waiting for a Python client for the openAPI offered by it. somewhere it says Determines the output encoding (text based 'CIF' or binary 'BCIF'). Ligands can also be exported as 'SDF', 'MOL', or 'MOL2'
Comments.UserDisplayName: pippo1980
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-19T21:38:06.323Z
Comments.Text: something like this https://github.com/williamgilpin/pypdb but for the modelserver
Comments.UserDisplayName: pippo1980
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-20T08:28:53.953Z
Comments.Text: well openapigenerator docs states all operation on api with Return type Void so probably its not the right server ?
Comments.UserDisplayName: pippo1980
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-21T13:49:55.810Z
Comments.Text: see https://bioinformatics.stackexchange.com/questions/8583/retrieve-id-ligand-from-pdb-file
Comments.UserDisplayName: pippo1980
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-21T13:50:10.483Z
Comments.Text: Does this answer your question? [Retrieve ID ligand from PDB file](https://bioinformatics.stackexchange.com/questions/8583/retrieve-id-ligand-from-pdb-file)
Comments.UserDisplayName: pippo1980
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-22T18:25:10.817Z
Comments.Text: Thank you everyone for your solution. I still did not figure out as I am totally new to this simulation field.
Comments.UserDisplayName: dnalectronics
Tags: <protein-structure><phylogenetics><pdb><drugs>
Title: Help me in understanding the PDB file
ThreadText: # Help me in understanding the PDB file
  
  (Asked by: username_0 on 2021-11-19)
  
  Can anybody please explain the below line to me.
  
  "We took the structure and coordinates of nogalamycin
  from the X-ray structure determined in PDB code = 1D17"
  
  What do I need to download from there....a pdb file or what?
  
  Thank you
  
  **Tags:** protein-structure, phylogenetics, pdb, drugs
  
  > **Comments:**
  > **username_1**: If you want to download the structure – yes, a PDB file or mmCIF file (different file formats with the same structure).  
  > **username_0**: Thank you so much for your reply. But the pdb file is about the complex molecule(ligand-DNA). The above line says "We took the structure and coordinates of nogalamycin from the X-ray structure determined". The pdb id page shows ligand structure separately. .... download CCD file or instance file. Do you think I need to download only ligand file?  
  > **username_1**: Ah, I overlooked that you are after the ligand only. Instance coordinates are taken from this structure (ligand extracted from the complex). Ideal coordinates are taken from the CCD (Chemical Component Dictionary) – the same ligand, but it's 3D structure doesn't need to be identical to the ligand in this complex. At least that's how I understand it. Another alternative is to download the PDB file with the whole structure and manually extract the ligand, but that's more cumbersome.  
  > **username_2**: there is a https://models.rcsb.org/       ModelServer,  The ModelServer is a service for accessing subsets of macromolecular model data. I am sure there is a way to get just the ligand. Waiting for a Python client for the openAPI offered by it. somewhere it says Determines the output encoding (text based 'CIF' or binary 'BCIF'). Ligands can also be exported as 'SDF', 'MOL', or 'MOL2'  
  > **username_2**: something like this https://github.com/williamgilpin/pypdb but for the modelserver  
  > **username_2**: well openapigenerator docs states all operation on api with Return type Void so probably its not the right server ?  
  > **username_2**: see https://bioinformatics.stackexchange.com/questions/8583/retrieve-id-ligand-from-pdb-file  
  > **username_2**: Does this answer your question? [Retrieve ID ligand from PDB file](https://bioinformatics.stackexchange.com/questions/8583/retrieve-id-ligand-from-pdb-file)  
  > **username_0**: Thank you everyone for your solution. I still did not figure out as I am totally new to this simulation field.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-11-22. Score: 1
  
  well wasnt able to figure out how to make openapigenerator work with rcsb pdb ModelServer <https://models.rcsb.org/>, I ended up with this code
  copying the webserver manual input results for ligands:
  
  ```
  import requests
  
  def main():
     
    risposta = requests.get('https://models.rcsb.org/v1/1d17/ligand?encoding=cif&copy_all_categories=false&download=true&filename=out',
                            
                            allow_redirects=True)
    
    open('out.cif', 'wb').write(risposta.content)
  
    print(risposta.status_code)
  
  if __name__ == '__main__':      
     
     main()
  
  ```
  
  unfortunately the server gives you the wrong ligand (try it out)
  
  it says :' ​/v1​/{id}​/ligand
  Coordinates of the first group satisfying the given criteria.'
  
  tried with:
  
  ```
  risposta = requests.get('https://models.rcsb.org/v1/1d17/ligand?label_atom_id=NGM&encoding=cif&copy_all_categories=false&download=true&filename=out',
                         
                         allow_redirects=True)
  
  ```
  
  but no luck again, think problem is in downloaded file :
  
  ```
  _model_server_params.name     atom_site 
  _model_server_params.value    '{"label_atom_id":"NGM"}'  ###### here
  
  ```
  
  but not an expert of APis and openAPI at all
  
  EDITED:
  
  eventually I got it right using in the code above:
  
  ```
  risposta = requests.get('https://models.rcsb.org/v1/1d17/ligand?label_comp_id=NGM&encoding=cif&copy_all_categories=false&download=true&filename=out',
                        
                        allow_redirects=True) 
  
  ```
  
  so I get a out.cif file containing NGM
  
  using another database and FTP :
  
  ```
  #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  Created on Fri Nov 19 19:29:30 2021
  
  @author: Pietro
  
  https://bioinformatics.stackexchange.com/questions/18076/help-me-in-understanding-the-pdb-file#comment25289_18076
  
  Ligand extract:
      
  https://stackoverflow.com/questions/61390035/how-to-save-each-ligand-from-a-pdb-file-separately-with-bio-pdb
  
  """
  
  from ftplib import FTP
  
  import gzip
  
  import os
  
  from Bio.PDB import PDBParser, PDBIO, Select
  
  def is_het(residue):
      res = residue.id[0]
      return res != " " and res != "W"
  
  class ResidueSelect(Select):
      def __init__(self, chain, residue):
          self.chain = chain
          self.residue = residue
  
      def accept_chain(self, chain):
          return chain.id == self.chain.id
  
      def accept_residue(self, residue):
          """ Recognition of heteroatoms - Remove water molecules """
          return residue == self.residue and is_het(residue)
  
  def extract_ligands(path):
      """ Extraction of the heteroatoms of .pdb files """
  
      for pfb_file in os.listdir(path):
          i = 1
          if pfb_file.endswith('.pdb') and not pfb_file.startswith("lig_"):
              pdb_code = pfb_file[:-4]
              pdb = PDBParser().get_structure(pdb_code, path + pfb_file)
              io = PDBIO()
              io.set_structure(pdb)
              for model in pdb:
                  for chain in model:
                      for residue in chain:
                          if not is_het(residue):
                              continue
                          print(f"saving {chain} {residue}")
                          io.save(f"lig_{pdb_code}_{i}.pdb", ResidueSelect(chain, residue))
                          i += 1
  
  def getFile(ftp, filename):
      try:
          # ftp.retrbinary("RETR", filename ,open(code+'.gz', 'wb').write)
          ftp.retrbinary("RETR " + filename ,open(code+'.gz', 'wb').write)
      except:
          print("Error somewhere !!!!")
  
  code = '1D17'
  filename = 'pdb'+code.lower()+'.ent.gz'                 ## pdb1D17.ent.gz    
  
  print(filename)
  
  ftp = FTP('ftp.wwpdb.org')   # connect to host, default port
  
  # ftp.login()               # user anonymous, passwd anonymous@
  print(ftp.login())
  
  ftp.cwd('/pub/pdb/data/structures/all/pdb/')  
  
  print(ftp.pwd()  )
  
  getFile(ftp, filename)
  
  zipped = gzip.open(code+'.gz', 'rb')
  
  unzipped = zipped.read()
  
  # print(unzipped)
  
  saved = open(code+'.pdb', 'wb')
  
  saved.write(unzipped)
  saved.close()
  
  path = './'
  
  extract_ligands(path)
  
  ```
  
  copying from : <https://stackoverflow.com/questions/61390035/how-to-save-each-ligand-from-a-pdb-file-separately-with-bio-pdb>
  
  and using FTP from ftplib on <http://ftp.wwpdb.org/pub/pdb/data/structures/all/pdb/> : PDB - FTP Archive over HTTP
  
  NOGALAMYCIN is NGM third ligand downloaded (shuold be the only one according to <https://www.rcsb.org/structure/1d17>)
  
  In any case I am failing at ubderstandung \*,-) how <https://models.rcsb.org/>
  
  Parameters are related to <https://pdb101.rcsb.org/learn/guide-to-understanding-pdb-data/beginner%E2%80%99s-guide-to-pdb-structures-and-the-pdbx-mmcif-format> , the mmcif format
  
  but as I told before I can't read inside openapi.json OpenAPI Specification
  
  
  ---
  
  