File: with_jligand.py

package info (click to toggle)
coot 1.1.18%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 219,964 kB
  • sloc: cpp: 495,934; python: 35,043; ansic: 26,143; lisp: 22,768; sh: 13,186; makefile: 2,746; awk: 441; xml: 245; csh: 14
file content (107 lines) | stat: -rw-r--r-- 3,955 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

# Define an environment variable for the place where jligand.jar
# resides in a canonical distribution
# 

# should be global?
to_jligand_secret_file_name = ".coot-to-jligand-8lcs"
global from_jligand_secret_file_name
from_jligand_secret_file_name = ".jligand-to-coot"

jligand_home = os.getenv("JLIGAND_HOME") if os.getenv("JLIGAND_HOME") else "."

java_command = "java"  # may have to absolute FIXME
jligand_jar = os.path.join(os.path.normpath(jligand_home), "jligand.jar")
jligand_args = ["-jar", jligand_jar, "-coot"]

def write_file_for_jligand(resname_1, resname_2):

    fin = open(to_jligand_secret_file_name, 'w')
    int_time = time.time()
    fin.write("CODE " + resname_1 + "\n")
    fin.write("CODE " + resname_2 + "\n")
    fin.write("TIME " + str(int_time) + "\n")
    fin.close()

if True:
  if coot_gui_api.main_menubar():
      
      menu = coot_gui.coot_menubar_menu("JLigand")

      def launch_jligand():
          if not os.path.isfile(jligand_jar):
              s = "jligand java jar file: " + jligand_jar + " not found"
              coot.info_dialog(s)
          else:
              java_exe = coot_utils.find_exe(java_command)
              if java_exe:
                  coot_utils.run_concurrently(java_exe, jligand_args)
              else:
                  print "BL INFO:: no java found"
          
      coot_gui.add_simple_coot_menu_menuitem(
          menu, "Launch Jligand",
          lambda func: launch_jligand()
          )


      def make_jligand_link():
          def link_em(*args):
              print "we received these clicks", args
              if (len(args) == 2):
                  click_1 = args[0]
                  click_2 = args[1]
                  if ((len(click_1) == 7)
                      and (len(click_2) ==7)):
                      resname_1 = coot.residue_name(click_1[1],
                                               click_1[2],
                                               click_1[3],
                                               click_1[4])
                      resname_2 = coot.residue_name(click_2[1],
                                               click_2[2],
                                               click_2[3],
                                               click_2[4])
                      if not (isinstance(resname_1, str) and
                              isinstance(resname_2, str)):
                          print "Bad resnames: %s and %s" %(resname_1, resname_2)
                      else:
                          write_file_for_jligand(resname_1, resname_2)
                          
          user_defined_click(2, link_em)
          
      coot_gui.add_simple_coot_menu_menuitem(
          menu, "Send Link to JLigand (click 2 monomers)",
          lambda func: make_jligand_link()
          )

def handle_read_from_jligand_file():
    global from_jligand_secret_file_name
    if (os.path.isfile(from_jligand_secret_file_name)):
        coot.read_cif_dictionary(from_jligand_secret_file_name)

global startup_mtime
startup_mtime = prodrg_import.get_file_latest_time(from_jligand_secret_file_name)

def jligand_timeout_func():
    
    global startup_mtime
    global from_jligand_secret_file_name

    import operator
    
    now_time = prodrg_import.get_file_latest_time(from_jligand_secret_file_name)
    #print "startup-mtime: %s   now-time: %s" %(startup_mtime, now_time)
    if operator.isNumberType(now_time):
        if not operator.isNumberType(startup_mtime):
            startup_mtime = now_time
            print "just set startup-mtime to (first)", startup_mtime
            handle_read_from_jligand_file()
        else:
            if (now_time > startup_mtime):
                startup_mtime = now_time
                print "just set startup-mtime to", startup_mtime
                handle_read_from_jligand_file()
                
    return True # we never expire...
                
gobject.timeout_add(500, jligand_timeout_func)