| 
  
    Please add the contact author to the list of Authors if that person is to appear on the paper!
   | 
"""
  
  return retstr
OV.registerFunction(publicationMetadataHtmlMaker)
def contactLetter():
  letterText = OV.get_cif_item('_publ_contact_letter','?','gui')
  if letterText is None:
    import datetime
    today = datetime.date.today()
    date = today.strftime("%x")
    journal = OV.get_cif_item('_publ_requested_journal')
    fileName = olx.FileName()
    authorList = OV.GetParam('snum.metacif.publ_author_names')
    authors = ''
    if authorList is None:
      numberAuthors = 0
    else:
      authorList = authorList.split(';')
      numberAuthors = len(authorList)
    for i in range(numberAuthors):
      author = authorList[i]
      if ',' in author:
        a = author.split(',')
        surname = a[0]
        initials = ''
        for forename in a[1].split():
          initials += '%s.' %forename[0].upper()
      else:
        a = author.split()
        surname = a[-1]
        initials = ''
        for forename in a[:-1]:
          initials += '%s.' %forename[0].upper()
      if i < numberAuthors - 2:
        authorAbbrev = initials + surname + ', '
      elif i == numberAuthors - 2:
        authorAbbrev = initials + surname + ' and '
      elif i > numberAuthors - 2:
        authorAbbrev = initials + surname
      authors += authorAbbrev
    letterText = """Date of submission %s
The CIF file contains data for the structure %s from
the paper 'ENTER PAPER TITLE' by
%s.
The paper will be submitted to %s.
""" %(date,fileName,authors,journal)
  inputText = OV.GetUserInput(0,'_publ_contact_letter',letterText)
  if inputText is not None:
    OV.set_cif_item('_publ_contact_letter', inputText);
  return ""
OV.registerFunction(contactLetter)
def move(arg,name):
  listNames = OV.GetParam('snum.metacif.publ_author_names').split(';')
  name_i = olx.GetValue(name)
  i = listNames.index(name_i)
  if arg.lower() == 'up':
    if i != 0:
      name_i_minus_1 = listNames[i-1]
      listNames[i] = name_i_minus_1
      listNames[i-1] = name_i
    else:
      pass
  elif arg.lower() == 'down':
    try:
      name_i_plus_1 = listNames[i+1]
      listNames[i] = name_i_plus_1
      listNames[i+1] = name_i
    except:
      pass
  elif arg in ('del','DEL'):
    del listNames[i]
  names = ';'.join(listNames)
  OV.SetParam('snum.metacif.publ_author_names', names)
  return ''
OV.registerFunction(move)
def restraint_builder(cmd):
  height = OV.GetParam('gui.html.combo_height')
  colspan = 3
  constraints = ["EXYZ", "EADP", "AFIX"]
  olex_conres = ["RRINGS", "TRIA", "ADPUEQ", "ADPVOL", "ANGLE", "DIANG"]
  html = []
  atom_pairs =  {
    "DFIX":["name_DFIX", "var_d: ", "var_s:0.02", "help_DFIX-use-help"],
    "DANG":["name_DANG", "var_d: ", "var_s:0.04", "help_Select atom pairs"],
    "SADI":["name_SADI", "var_s:0.02", "help_SADI-use-help"],
  }
  atom_names =  {
    "SAME":["name_SAME", "var_s1:0.02", "var_s2:0.02", "help_Select any number of atoms"],
    "CHIV":["name_CHIV", "var_V:0", "var_s:0.1", "help_Select any number of atoms"],
    "FLAT":["name_FLAT", "var_s1:0.1", "help_Select at least four atoms"],
    "DELU":["name_DELU", "var_s1:0.01", "var_s2:0.01", "help_Select any number of atoms"],
    "SIMU":["name_SIMU", "var_s:0.04", "var_st:0.08", "var_dmax:1.7", "help_Select any number of atoms"],
    "ISOR":["name_ISOR", "var_s:0.1", "var_st:0.2", "help_Select any number of atoms"],
    "EXYZ":["name_EXYZ", "help_exyz-htmhelp"],
    "EADP":["name_EADP", "help_eadp-htmhelp"],
    "AFIX":["name_AFIX", "var_m:6;5;10;11", "var_n:6;9", "help_AFIX-use-help"],
#    "RRINGS":["name_RRINGS", "var_d:1.39 ", "var_s1:0.02", "help_rrings-htmhelp"],
    "RRINGS":["name_RRINGS", "help_rrings-htmhelp"],
    "TRIA":["name_TRIA", "var_d: ", "var_angle: ", "help_tria-htmhelp"],
    "ADPUEQ":["name_ADPUEQ", "var_n:0.05 ", "help_adpueq-htmhelp", "cmd_restrain adp ueq"],
    "ADPVOL":["name_ADPVOL", "help_adpvol-htmhelp", "cmd_restrain adp volume"],
    "ANGLE":["name_ANGLE", "var_n: ", "help_angle-htmhelp", "cmd_restrain angle"],
    "DIANG":["name_DIANG", "var_n: ", "help_diang-htmhelp", "cmd_restrain dihedral"],
  }
  if atom_pairs.has_key(cmd):
    l = atom_pairs[cmd]
  elif atom_names.has_key(cmd):
    l = atom_names[cmd]
  else:
    return "Please atoms and restraint, then press GO"
  onclick = ""
  pre_onclick = ""
  post_onclick = ""
  html_help = "Click on the help link for more info"
  itemcount = 0
  items = None
  var = None
  ib = ""
  varcount = 0
  cmd = ""
  for item in l:
    if "var" in item:
      varcount += 1
    if "cmd" in item:
      cmd = item.split("_")[1]
  for item in l:
    itemcount += 1
    id = item.split("_")[0]
    tem = item.split("_")[1]
    val = ""
    if ":" in tem:
      var = tem.split(":")[0]
      val = tem.split(":")[1]
    if id == "name":
      name = tem
      if not cmd:
        onclick += "%s " %name
      else:
        onclick += "%s " %cmd
    elif id == "help":
      html_help = OV.TranslatePhrase(tem)
      html_help, d = htmlTools.format_help(html_help)
    elif id == "cmd":
      cmd = val
    elif id == "var":
      ctrl_name = "%s_%s_TEXT_BOX" %(name, var)
      pre_onclick += "SetVar\(%s_value,GetValue\(%s))>>" %(ctrl_name,ctrl_name)
      onclick += "GetValue\(%s) " %ctrl_name
      if val == " ":
        val = "$GetVar(%s_value,'')" %ctrl_name
      elif ';' in val:
        items = val
        val = items.split(';')[0]
      else:
        items = None
        val = val.strip()
      if items:
        width='100%'
      else:
        width='100%'
      if var == "d":
        width='100%'
      width='33%'
      b_width='60%'
      if name == 'AFIX':
        width='50%'
        b_width='80%'
      d = {"ctrl_name":ctrl_name,
           "label":var,
           "valign":'center',
           "value":val,
           "width":b_width,
           "height":height,
           "bgcolor":"$GetVar(HtmlInputBgColour))"
           }
      if items:
        d.setdefault("items",items)
      if var:
        ib += "