#!/usr/bin/env python3
# pylint: disable=missing-function-docstring
from __future__ import print_function
import panel as pn
from panel_chemistry . widgets import JSMEEditor
from panel . interact import interact
import os
import sys
from panel_chemistry . pane import NGLViewer
from panel_chemistry . pane . ngl_viewer import EXTENSIONS
import py3Dmol
from panel_chemistry . pane import Py3DMol
import subprocess
import uuid
# from iodata import IOData
def test_can_construct ( ) :
JSMEEditor ( )
def cmmde_gui ( ) :
geom = ' '
pn . extension ( " jsme " , sizing_mode = " stretch_width " )
editor = JSMEEditor ( value = " " , height = 500 , format = " smiles " , subscriptions = [ ' smiles ' ] )
# Terminal widget
TextArea = pn . widgets . TextAreaInput ( value = " Computational Molecular and Material Design Environment \n Authors: \n Universitas Pertamina \n Institut Teknologi Sumatera \n Masyarakat Komputasi Indonesia \n \n " ,
height = 500
)
# CMMDE software options
software_btn = pn . widgets . Select ( name = " Software selections " , value = ' Orca ' , options = [ ' Orca ' , ' GROMACS ' , ' Dcdftbmd ' , ' Quantum Espresso ' ] )
software = { ' Orca ' : ' orca ' , ' GROMACS ' : ' gromacs ' , ' Dcdftbmd ' : ' dcdftb ' , ' Quantum Espresso ' : ' qe ' }
# CMMDE job options
job_btn = pn . widgets . MultiSelect ( name = " Job selections " , value = [ ' Single point calculation ' ] , options = [ ' Single point calculation ' , ' Geometry optimization ' , ' Frequency calculation ' , ' Molecular dynamics ' , ' Metadynamics ' ] )
job = { ' Single point calculation ' : ' sp ' , ' Geometry optimization ' : ' opt ' , ' Frequency calculation ' : ' freq ' , ' Molecular dynamics ' : ' md ' , ' Metadynamics ' : ' mtd ' }
# CMMDE method options
method_btn = pn . widgets . Select ( name = " Method selections " , value = ' GFN2-xTB ' , options = [ ' GFN2-xTB ' , ' GFN1-xTB ' , ' DFTB2 ' , ' DFTB2-gammah ' , ' DFTB3 ' , ' DFTB3-diag ' ] )
method = { ' GFN2-xTB ' : ' XTB2 ' , ' GFN1-xTB ' : ' XTB1 ' , ' DFTB2 ' : ' DFTB2 ' , ' DFTB2-gammah ' : ' DFTB2_gammah ' , ' DFTB3 ' : ' DFTB3 ' , ' DFTB3-diag ' : ' DFTB3-diag ' }
# Name your molecule/Materialmaterial
Name_input = pn . widgets . TextInput ( name = " Molecule name " )
# CMMDE running button
Run_btn = pn . widgets . Button ( name = " Run CMMDE! " , button_type = ' primary ' )
# RunMessage = pn.widgets.StaticText()
def run ( event ) :
# RunMessage.value = " "
# terminal.clear()
unik = str ( uuid . uuid4 ( ) . hex )
Folder = Name_input . value + " _ " + unik
os . makedirs ( Folder )
os . chdir ( Folder )
job_list = [ job [ i ] for i in job_btn . value ]
jobs = " , " . join ( job_list )
cmd = subprocess . run ( [ " cmmde.py " , " -i " , " {} " . format ( editor . value ) , " -s " , " {} " . format ( software [ software_btn . value ] ) , " -j " , " {} " . format ( jobs ) , " -m " , " {} " . format ( method [ method_btn . value ] ) ] )
#terminal.subprocess.run("cmmde.py","-i{}".format(editor.value),"-s{}".format(software[software_btn.value]), "-j{}".format(jobs), "-m{}".format(method[method_btn.value]))
TextArea . value = TextArea . value + " \n " + " Perhitungan anda telah tersubmit! "
# RunMessage.value = "Perhitungan telah tersubmit!"
Run_btn . on_click ( run )
# Upload structure button
structure_input = pn . widgets . FileInput ( )
# Post calculations
post_calc = { ' Frequency calculation ' : ' freq ' , ' Radial distribution function ' : ' rdf ' , ' Mean Square Displacement ' : ' msd ' , ' Time-dependent calculation ' : ' td ' , ' Thermochemistry calculation ' : ' thermo ' }
post_btn = pn . widgets . Select ( name = " Job Selection " , value = ' Frequency calculation ' , options = [ ' Frequency calculation ' , ' Radial distribution function ' , ' Mean Square Displacement ' , ' Time-dependent calculation ' , ' Thermochemistry calculation ' ] )
# Post Calculation CMMDE software options
post_software_btn = pn . widgets . Select ( name = " Software selections for post calculations " , value = ' Orca ' , options = [ ' Orca ' , ' GROMACS ' , ' Dcdftbmd ' , ' Quantum Espresso ' ] )
post_software = { ' Orca ' : ' orca ' , ' GROMACS ' : ' gromacs ' , ' Dcdftbmd ' : ' dcdftb ' , ' Quantum Espresso ' : ' qe ' }
# Post CMMDE method options
post_method_btn = pn . widgets . Select ( name = " Method selections for post calculations " , value = ' GFN2-xTB ' , options = [ ' GFN2-xTB ' , ' GFN1-xTB ' , ' DFTB2 ' , ' DFTB2-gammah ' , ' DFTB3 ' , ' DFTB3-diag ' ] )
post_method = { ' GFN2-xTB ' : ' XTB2 ' , ' GFN1-xTB ' : ' XTB1 ' , ' DFTB2 ' : ' DFTB2 ' , ' DFTB2-gammah ' : ' DFTB2_gammah ' , ' DFTB3 ' : ' DFTB3 ' , ' DFTB3-diag ' : ' DFTB3-diag ' }
def post_calculation ( event ) :
# terminal.clear()
if post_calc [ post_btn . value ] == ' thermo ' and post_software [ post_software_btn . value ] == ' orca ' :
cmd = subprocess . run ( [ " cmmdepost.py " , " -j " , " {} " . format ( post_calc [ post_btn . value ] ) , " -s " , " {} " . format ( post_software [ post_software_btn . value ] ) ] , capture_output = True , text = True )
TextArea . value = TextArea . value + " \n " + cmd . stdout
# terminal.subprocess.run("cmmdepost.py","-j{}".format(post_calc[post_btn.value]),"-s{}".format(post_software[post_software_btn.value]))
else :
os . makedirs ( post_calc [ post_btn . value ] )
os . chdir ( post_calc [ post_btn . value ] )
cmd = subprocess . run ( [ " cmmde.py " , " -i " , " {} " . format ( " ../cmmd.xyz " ) , " -s " , " {} " . format ( post_software [ post_software_btn . value ] ) , " -j " , " {} " . format ( post_calc [ post_btn . value ] ) , " -m " , " {} " . format ( post_method [ post_method_btn . value ] ) ] , capture_output = True , text = True )
# terminal.subprocess.run("cmmde.py","-i{}".format("../cmmd.xyz"),"-s{}".format(post_software[post_software_btn.value]), "-j{}".format(post_calc[post_btn.value]), "-m{}".format(post_method[post_method_btn.value]))
TextArea . value = TextArea . value + " \n " + cmd . stdout
runpost_btn = pn . widgets . Button ( name = " Run post calculation! " , button_type = ' primary ' )
runpost_btn . on_click ( post_calculation )
# Check the progress
def progress ( event ) :
# terminal.clear()
# terminal.subprocess.run("squeue")
cmd = subprocess . run ( [ " squeue " ] , capture_output = True , text = True )
TextArea . value = TextArea . value + " \n " + cmd . stdout
Progress_btn = pn . widgets . Button ( name = " Check calculation " , button_type = ' primary ' )
Progress_btn . on_click ( progress )
# Check the output
def check_out ( event ) :
cmd = subprocess . run ( [ " tail " , " -f " , " cmmd.out " ] , capture_output = True , text = True )
cmd . stdout
checkout_btn = pn . widgets . Button ( name = " Check output " , button_type = ' primary ' )
checkout_btn . on_click ( check_out )
# Visualize the results
xyzview = py3Dmol . view ( )
xyzview . setBackgroundColor ( ' 0xeeeeee ' )
xyzview . zoomTo ( )
xyzviewer = Py3DMol ( xyzview , height = 400 , sizing_mode = " stretch_width " , name = " CMMDE viewer " )
def visualize ( event ) :
with open ( ' cmmd.xyz ' , ' r ' ) as f :
xyz = f . read ( )
xyzview . addModel ( xyz , ' xyz ' )
xyzview . setStyle ( ' stick ' )
xyzviewer . object = xyzview
# xyzviewer.object = xyzview
visual_btn = pn . widgets . Button ( name = " Visualize! " , button_type = ' primary ' )
visual_btn . on_click ( visualize )
def set_background ( color = ' 0xeeeeee ' ) :
xyzview . setBackgroundColor ( color )
xyzviewer . param . trigger ( " object " )
set_background ( " #e6f6ff " )
accent = " #0072B5 "
# background = pn.widgets.ColorPicker(value="#e6f6ff", name="Background")
# pn.bind(set_background, color=background, watch=True)
# def set_style(style="stick"):
# xyzview.setStyle({style: {}})
# xyzview.zoomTo()
# xyzviewer.param.trigger("object")
# set_style("stick")
# style=pn.widgets.RadioButtonGroup(value="stick", options=["stick", "sphere"], name="Style", button_type="success")
# set_style=pn.bind(set_style, style=style, watch=True)
#### Wrap them all together ##########
return pn . template . MaterialTemplate (
site = " CMMDE-GUI " ,
title = " CMMDE Editor " ,
main = [ editor , TextArea , visual_btn , pn . Tabs ( xyzviewer ) ] ,
sidebar = [ pn . Row ( software_btn ) , Name_input , pn . Card ( job_btn , method_btn , pn . Row ( Run_btn , Progress_btn ) , title = " Main Calculation " , collapsed = True ) , pn . Card ( post_btn , post_software_btn , post_method_btn , pn . Row ( runpost_btn , Progress_btn ) , title = " Post Calculation " , collapsed = True ) ] ,
header_background = accent , accent_base_color = accent
)
if __name__ . startswith ( " bokeh " ) :
cmmde_gui ( ) . servable ( )