#!/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
# 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
terminal = pn . widgets . Terminal (
" Computational Molecular and Material Design Environment \n Authors: \n Universitas Pertamina \n Institut Teknologi Sumatera \n Masyarakat Komputasi Indonesia \n \n " ,
options = { " cursorBlink " : True } ,
height = 200 , sizing_mode = ' stretch_width '
)
# CMMDE software options
software_btn = pn . widgets . MultiSelect ( 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 . MultiChoice ( 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 . MultiChoice ( 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 ' )
def run ( event ) :
os . makedirs ( Name_input . value )
os . chdir ( Name_input . value )
terminal . subprocess . run ( " cmmde.py " , " -i {} " . format ( editor . value ) , " -s {} " . format ( software [ software_btn . value [ 0 ] ] ) , " -j {} " . format ( job [ job_btn . value [ 0 ] ] ) , " -m {} " . format ( method [ method_btn . value [ 0 ] ] ) )
Run_btn . on_click ( run )
# Post calculations
post_btn = pn . widgets . MultiChoice ( name = " Post calculation " , value = [ ' Frequency calculation ' ] , options = [ ' Frequency calculation ' , ' Radial distribution function ' , ' Mean Square Displacement ' , ' Time-dependent calculation ' , ' Thermochemistry calculation ' ] )
post_calc = { ' Frequency calculation ' : ' freq ' , ' Radial distribution function ' : ' rdf ' , ' Mean Square Displacement ' : ' msd ' , ' Time-dependent calculation ' : ' td ' , ' Thermochemistry ' : ' thermo ' }
def post_calculation ( event ) :
os . makedirs ( post_calc [ post_btn . value [ 0 ] ] )
os . chdir ( post_calc [ post_btn . value [ 0 ] ] )
if post_calc [ post_btn . value [ 0 ] ] == ' thermo ' and software [ software_btn . value [ 0 ] ] == ' orca ' :
terminal . subprocess . run ( " cmmdepost.py " , " -j {} " . format ( post_calc [ post_btn . value [ 0 ] ] ) , " -s {} " . format ( software [ software_btn . value [ 0 ] ] ) )
else :
terminal . subprocess . run ( " cmmde.py " , " -i {} " . format ( " ../cmmd.xyz " ) , " -s {} " . format ( software [ software_btn . value [ 0 ] ] ) , " -j {} " . format ( post_calc [ post_btn . value [ 0 ] ] ) , " -m {} " . format ( method [ method_btn . value [ 0 ] ] ) )
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 . subprocess . run ( " squeue " )
Progress_btn = pn . widgets . Button ( name = " Check calculation " , button_type = ' primary ' )
Progress_btn . on_click ( progress )
# 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 , terminal , terminal . subprocess . param . running , visual_btn , pn . Tabs ( xyzviewer ) ] ,
sidebar = [ pn . Row ( software_btn , height = 200 ) , Name_input , pn . Column ( job_btn , height = 400 ) , pn . Column ( method_btn , height = 400 ) , pn . Row ( Run_btn , Progress_btn ) , pn . Column ( post_btn , height = 400 ) , pn . Row ( runpost_btn , Progress_btn ) ] ,
header_background = accent , accent_base_color = accent
)
if __name__ . startswith ( " bokeh " ) :
cmmde_gui ( ) . servable ( )