igashov commited on
Commit
0673854
1 Parent(s): 81748f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -8,14 +8,14 @@ HTML_TEMPLATE = """<!DOCTYPE html>
8
  <head>
9
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10
  <style>
11
- .mol-container {
12
  width: 600px;
13
  height: 600px;
14
  position: relative;
15
- }
16
- .mol-container select{
17
  background-image:None;
18
- }
19
  </style>
20
  <script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
21
  </head>
@@ -23,14 +23,14 @@ HTML_TEMPLATE = """<!DOCTYPE html>
23
  <body>
24
  <div id="container" class="mol-container"></div>
25
  <script>
26
- $(document).ready(function() {
27
  let element = $("#container");
28
- let config = { backgroundColor: "orange" };
29
  let viewer = $3Dmol.createViewer( element, config );
30
- viewer.addSphere({ center: {x:0, y:0, z:0}, radius: 10.0, color: "green" });
31
  viewer.zoomTo();
32
  viewer.render();
33
- });
34
  </script>
35
  </body>
36
  </html>
@@ -41,13 +41,21 @@ display-capture; encrypted-media;" sandbox="allow-modals allow-forms allow-scrip
41
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
42
  allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>"""
43
 
 
 
 
 
 
 
44
  def generate(input_file):
45
  try:
46
  path = input_file.name
 
 
47
  except:
48
  return 'Error: could not open the provided file'
49
 
50
- html = HTML_TEMPLATE
51
  return IFRAME_TEMPLATE.format(html=html)
52
 
53
 
 
8
  <head>
9
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10
  <style>
11
+ .mol-container {{
12
  width: 600px;
13
  height: 600px;
14
  position: relative;
15
+ }}
16
+ .mol-container select{{
17
  background-image:None;
18
+ }}
19
  </style>
20
  <script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
21
  </head>
 
23
  <body>
24
  <div id="container" class="mol-container"></div>
25
  <script>
26
+ $(document).ready(function() {{
27
  let element = $("#container");
28
+ let config = {{ backgroundColor: "orange" }};
29
  let viewer = $3Dmol.createViewer( element, config );
30
+ viewer.addModel(`{molecule}`, "{fmt}")
31
  viewer.zoomTo();
32
  viewer.render();
33
+ }});
34
  </script>
35
  </body>
36
  </html>
 
41
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
42
  allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>"""
43
 
44
+
45
+ def read_molecule(path):
46
+ with open(path, "r") as f:
47
+ return "".join(f.readlines())
48
+
49
+
50
  def generate(input_file):
51
  try:
52
  path = input_file.name
53
+ molecule = read_molecule(path)
54
+ fmt = path.split('.')[-1]
55
  except:
56
  return 'Error: could not open the provided file'
57
 
58
+ html = HTML_TEMPLATE.format(molecule=molecule, fmt=fmt)
59
  return IFRAME_TEMPLATE.format(html=html)
60
 
61