code: #!/usr/bin/env python
  # coding: utf-8
  
  # In[1]:
  
  
  #@title Input protein sequence(s), then hit `Runtime` -> `Run all`
  #from google.colab import files
  import os.path
  import re
  import hashlib
  import random
  
  def add_hash(x,y):
      return x+"_"+hashlib.sha1(y.encode()).hexdigest()[:5]
  
  
  with open("protein") as f:
      query_sequence = f.read()
  #query_sequence = '' #@param {type:"string"}
  #@markdown  - Use `:` to specify inter-protein chainbreaks for **modeling complexes** (supports homo- and hetro-oligomers). For example **PI...SK:PI...SK** for a mono-dimer
  
  # remove whitespaces
  query_sequence = "".join(query_sequence.split())
  
  jobname = 'test' #@param {type:"string"}
  # remove whitespaces
  basejobname = "".join(jobname.split())
  basejobname = re.sub(r'\W+', '', basejobname)
  jobname = add_hash(basejobname, query_sequence)
  while os.path.isfile(f"{jobname}.csv"):
      jobname = add_hash(basejobname, ''.join(random.sample(query_sequence,len(query_sequence))))
  
  with open(f"{jobname}.csv", "w") as text_file:
      text_file.write(f"id,sequence\n{jobname},{query_sequence}")
  
  queries_path=f"{jobname}.csv"
  
  # number of models to use
  use_amber = False #@param {type:"boolean"}
  use_templates = False #@param {type:"boolean"}
  #save_to_google_drive = False #@param {type:"boolean"}
  #@markdown -  if the save_to_google_drive option was selected, the result zip will be uploaded to your Google Drive
  
  #@markdown ### Advanced settings
  msa_mode = "MMseqs2 (UniRef+Environmental)" #@param ["MMseqs2 (UniRef+Environmental)", "MMseqs2 (UniRef only)","single_sequence","custom"]
  model_type = "auto" #@param ["auto", "AlphaFold2-ptm", "AlphaFold2-multimer"]
  #@markdown  - "auto" = protein structure prediction using "AlphaFold2-ptm" and complex prediction "AlphaFold-multimer". For complexes "AlphaFold-multimer" and "AlphaFold-ptm" can be used.
  pair_mode = "unpaired+paired" #@param ["unpaired+paired","paired","unpaired"] {type:"string"}
  #@markdown - "unpaired+paired" = pair sequences from same species and add unpaired MSA, "unpaired" = generate seperate MSA for each chain, "paired" - only use sequences that were sucessfully paired.
  num_recycles = 1 #@param [1,3,6,12,24,48] {type:"raw"}
  
  #@markdown Don't forget to hit `Runtime` -> `Run all` after updating the form.
  
  # decide which a3m to use
  if msa_mode.startswith("MMseqs2"):
      a3m_file = f"{jobname}.a3m"
  elif msa_mode == "custom":
      a3m_file = f"{jobname}.custom.a3m"
      if not os.path.isfile(a3m_file):
          custom_msa_dict = files.upload()
          custom_msa = list(custom_msa_dict.keys())[0]
          header = 0
          import fileinput
          for line in fileinput.FileInput(custom_msa,inplace=1):
              if line.startswith(">"):
                  header = header + 1
              if not line.rstrip():
                  continue
              if line.startswith(">") == False and header == 1:
                   query_sequence = line.rstrip()
                      
              print(line, end='')
  
          os.rename(custom_msa, a3m_file)
          queries_path=a3m_file
          print(f"moving {custom_msa} to {a3m_file}")
  else:
      a3m_file = f"{jobname}.single_sequence.a3m"
      with open(a3m_file, "w") as text_file:
          text_file.write(">1\n%s" % query_sequence)
  
          
  # Removed
  #if save_to_google_drive:
  #    from pydrive.drive import GoogleDrive
  #    from pydrive.auth import GoogleAuth
  #    from google.colab import auth
  #    from oauth2client.client import GoogleCredentials
  #    auth.authenticate_user()
  #    gauth = GoogleAuth()
  #    gauth.credentials = GoogleCredentials.get_application_default()
  #    drive = GoogleDrive(gauth)
  #    print("You are logged into Google Drive and are good to go!")
  
  
  # In[ ]:
  
  
  #@title Run Prediction
  
  import sys
  
  from colabfold.download import download_alphafold_params, default_data_dir
  from colabfold.utils import setup_logging
  from colabfold.batch import get_queries, run, set_model_type
  
  from colabfold.colabfold import plot_protein
  from pathlib import Path
  import matplotlib.pyplot as plt
  
  
  # For some reason we need that to get pdbfixer to import
  if use_amber and '/usr/local/lib/python3.7/site-packages/' not in sys.path:
      sys.path.insert(0, '/usr/local/lib/python3.7/site-packages/')
  
  def prediction_callback(unrelaxed_protein, length, prediction_result, input_features):
      fig = plot_protein(unrelaxed_protein, Ls=length, dpi=100)
      plt.show()
      plt.close()
  
  result_dir="."
  setup_logging(Path(".").joinpath("log.txt"))
  queries, is_complex = get_queries(queries_path)
  model_type = set_model_type(is_complex, model_type)
  download_alphafold_params(model_type, Path("."))
  run(
      queries=queries,
      result_dir=result_dir,
      use_templates=use_templates,
      use_amber=use_amber,
      msa_mode=msa_mode,    
      model_type=model_type,
      num_models=5,
      num_recycles=num_recycles,
      model_order=[1, 2, 3, 4, 5],
      is_complex=is_complex,
      data_dir=Path("."),
      keep_existing_results=False,
      recompile_padding=1.0,
      rank_by="auto",
      pair_mode=pair_mode,
      stop_at_score=float(100),
      prediction_callback=prediction_callback,
  )
  
  
  # In[ ]:
  
  
  
  
  
apis: matplotlib.pyplot.show matplotlib.pyplot.close