title: How to synthesize this python function
body: <p>I am trying to make a code more compact. I think there is a part that can be nicely reduced but am not sure how to do it. I put a comment inside the code copied below for you to find it fast.</p>
  
  <p>The code is the next one:</p>
  
  <pre><code>def change_to_mop_gen(infile, namedir="",charge=0, gnorm=None, separate=True, hamiltonian="PM6", calctype="opt", multiplicity="singlet", eps=None, cycles=None):
  #armado de la salida
      if calctype=="thermo(298,298,0)":
          calctype1="thermo"
      else: 
          calctype1=calctype
      outfile=infile.split(".")[0] + "-" + calctype1 + "-" + hamiltonian
  
  #~ here comes the set of if / else sentences i think could be reduced
  
      if gnorm !=None:
          gnorm="gnorm=" + str(gnorm)
      else:
          gnorm= " "
      if cycles!=None:
          cycles="cycles="+str(cycles)
      else:
          cycles=""
      if separate==True:
          outfile=outfile + "_*.mop"
      else:
          outfile=outfile + ".mop"
      if eps !=None:
          eps="eps=" + str(eps)
      else:
          eps = ""  
  
      #~here it ends
  
      keywords = "-xk '%s  %s %s %s %s %s charge=%i'"%(cycles, hamiltonian, calctype, multiplicity, eps, gnorm, charge)
      #change directory of outfile
      if namedir!="":
          outfile= namedir + "/" + outfile
      return change_format(infile,outfile, keywords)
  </code></pre>
  
  <p>Any help would be good. </p>