Spaces:
Runtime error
Runtime error
igashov
commited on
Commit
·
f9310fd
1
Parent(s):
4f94923
output files
Browse files
app.py
CHANGED
|
@@ -105,7 +105,11 @@ def generate(input_file):
|
|
| 105 |
path = input_file.name
|
| 106 |
molecule = read_molecule(path)
|
| 107 |
name = '.'.join(path.split('/')[-1].split('.')[:-1])
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
print(f'Input path={path}, name={name}')
|
| 110 |
except Exception as e:
|
| 111 |
return f'Could not read the molecule: {e}'
|
|
@@ -113,6 +117,10 @@ def generate(input_file):
|
|
| 113 |
if molecule.GetNumAtoms() > 50:
|
| 114 |
return f'Too large molecule: upper limit is 50 heavy atoms'
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
positions, one_hot, charges = parse_molecule(molecule, is_geom=True)
|
| 117 |
anchors = np.zeros_like(charges)
|
| 118 |
fragment_mask = np.ones_like(charges)
|
|
@@ -138,9 +146,9 @@ def generate(input_file):
|
|
| 138 |
print('Generated linker')
|
| 139 |
x = chain[0][:, :, :ddpm.n_dims]
|
| 140 |
h = chain[0][:, :, ddpm.n_dims:]
|
| 141 |
-
save_xyz_file('results', h, x, node_mask, names=[name], is_geom=True, suffix='
|
| 142 |
print('Saved XYZ file')
|
| 143 |
-
subprocess.run(f'obabel
|
| 144 |
print('Converted to SDF')
|
| 145 |
break
|
| 146 |
|
|
@@ -148,7 +156,7 @@ def generate(input_file):
|
|
| 148 |
html = HTML_TEMPLATE.format(molecule=generated_molecule, fmt='sdf')
|
| 149 |
return [
|
| 150 |
IFRAME_TEMPLATE.format(html=html),
|
| 151 |
-
out_sdf,
|
| 152 |
]
|
| 153 |
|
| 154 |
|
|
@@ -165,8 +173,9 @@ with demo:
|
|
| 165 |
button = gr.Button('Generate Linker!')
|
| 166 |
|
| 167 |
gr.Markdown('')
|
|
|
|
| 168 |
visualization = gr.HTML()
|
| 169 |
-
output_files = gr.File(file_count="
|
| 170 |
|
| 171 |
button.click(
|
| 172 |
fn=generate,
|
|
|
|
| 105 |
path = input_file.name
|
| 106 |
molecule = read_molecule(path)
|
| 107 |
name = '.'.join(path.split('/')[-1].split('.')[:-1])
|
| 108 |
+
inp_sdf = f'results/{name}_input.sdf'
|
| 109 |
+
inp_xyz = f'results/{name}_input.xyz'
|
| 110 |
+
out_sdf = f'results/{name}_output.sdf'
|
| 111 |
+
out_xyz = f'results/{name}_output.xyz'
|
| 112 |
+
|
| 113 |
print(f'Input path={path}, name={name}')
|
| 114 |
except Exception as e:
|
| 115 |
return f'Could not read the molecule: {e}'
|
|
|
|
| 117 |
if molecule.GetNumAtoms() > 50:
|
| 118 |
return f'Too large molecule: upper limit is 50 heavy atoms'
|
| 119 |
|
| 120 |
+
with Chem.SDWriter(inp_sdf) as w:
|
| 121 |
+
w.write(molecule)
|
| 122 |
+
Chem.MolToXYZFile(molecule, inp_xyz)
|
| 123 |
+
|
| 124 |
positions, one_hot, charges = parse_molecule(molecule, is_geom=True)
|
| 125 |
anchors = np.zeros_like(charges)
|
| 126 |
fragment_mask = np.ones_like(charges)
|
|
|
|
| 146 |
print('Generated linker')
|
| 147 |
x = chain[0][:, :, :ddpm.n_dims]
|
| 148 |
h = chain[0][:, :, ddpm.n_dims:]
|
| 149 |
+
save_xyz_file('results', h, x, node_mask, names=[name], is_geom=True, suffix='output')
|
| 150 |
print('Saved XYZ file')
|
| 151 |
+
subprocess.run(f'obabel {out_xyz} -O {out_sdf}', shell=True)
|
| 152 |
print('Converted to SDF')
|
| 153 |
break
|
| 154 |
|
|
|
|
| 156 |
html = HTML_TEMPLATE.format(molecule=generated_molecule, fmt='sdf')
|
| 157 |
return [
|
| 158 |
IFRAME_TEMPLATE.format(html=html),
|
| 159 |
+
[inp_sdf, inp_xyz, out_sdf, out_xyz],
|
| 160 |
]
|
| 161 |
|
| 162 |
|
|
|
|
| 173 |
button = gr.Button('Generate Linker!')
|
| 174 |
|
| 175 |
gr.Markdown('')
|
| 176 |
+
gr.Markdown('## Output')
|
| 177 |
visualization = gr.HTML()
|
| 178 |
+
output_files = gr.File(file_count="multiple", label="Output Files")
|
| 179 |
|
| 180 |
button.click(
|
| 181 |
fn=generate,
|