Skip to content

Commit

Permalink
Octopus input generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sozykinsa committed Feb 25, 2024
1 parent c81246d commit 4c54c4d
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 72 deletions.
16 changes: 16 additions & 0 deletions src/program/octopus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from core_atomistic.atomic_model import AtomicModel


def model_to_octopus_input(model: AtomicModel):
"""
C 0.000 1.396 0.000
H -2.147 1.240 0.000
"""

text = ""
n_atoms = model.n_atoms()

for i in range(n_atoms):
text += str(model[i].let) + " " + model[i].xyz_string + "\n"
return text
35 changes: 28 additions & 7 deletions src/qtbased/gui4dftform.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from program.vasp import TVASP, vasp_dos, model_to_vasp_poscar
from program.dftb import model_to_dftb_d0
from program.lammps import model_to_lammps_input
from program.octopus import model_to_octopus_input
from program import crystal
from program import ase
from program.fdfdata import TFDFFile
Expand Down Expand Up @@ -174,6 +175,7 @@ def setup_ui(self): # pragma: no cover
self.ui.crystal_3d_d12_generate.clicked.connect(self.d12_3D_to_form)
self.ui.dftb_0d_generate.clicked.connect(self.dftb_0D_to_form)
self.ui.lammps_generate.clicked.connect(self.lammps_to_form)
self.ui.octopus_generate.clicked.connect(self.octopus_to_form)

self.ui.data_from_form_to_input_file.clicked.connect(self.data_from_form_to_input_file)
self.ui.model_rotation_x.valueChanged.connect(self.model_orientation_changed)
Expand Down Expand Up @@ -212,7 +214,8 @@ def setup_ui(self): # pragma: no cover
self.ui.plot_bands.clicked.connect(self.plot_bands)
self.ui.parse_bands.clicked.connect(self.parse_bands)
self.ui.FormActionsButtonPlotPDOSselected.clicked.connect(self.plot_selected_pdos)
self.ui.FormModifyCellButton.clicked.connect(self.edit_cell)
self.ui.modify_cell_cart_coord.clicked.connect(self.edit_cell)
self.ui.modify_cell_frac_coord.clicked.connect(self.modify_cell_frac_coord)
self.ui.FormActionsPostButGetBonds.clicked.connect(self.get_bonds)
self.ui.PropertyAtomAtomDistanceGet.clicked.connect(self.get_bond)
self.ui.FormStylesFor2DGraph.clicked.connect(self.set_2d_graph_styles)
Expand Down Expand Up @@ -747,9 +750,11 @@ def atom_delete(self):
return
if self.ui.openGLWidget.selected_atom < 0:
return
self.models[self.active_model_id].delete_atom(self.ui.openGLWidget.selected_atom)
self.models.append(deepcopy(self.models[self.active_model_id]))
self.fill_models_list()
self.models[-1].delete_atom(self.ui.openGLWidget.selected_atom)
self.history_of_atom_selection = []
self.model_to_screen(self.active_model_id)
self.model_to_screen(-1)

def atom_modify(self):
if len(self.models) == 0:
Expand Down Expand Up @@ -1008,6 +1013,11 @@ def edit_cell(self):
self.models.append(self.ui.openGLWidget.main_model)
self.model_to_screen(-1)

def modify_cell_frac_coord(self):
if len(self.models) == 0:
return
print("Not implemented")

def get_file_name_from_save_dialog(self, file_mask): # pragma: no cover
result = QFileDialog.getSaveFileName(self, 'Save File', self.work_dir, file_mask,
options=QFileDialog.DontUseNativeDialog)
Expand Down Expand Up @@ -2844,9 +2854,10 @@ def data_from_form_to_input_file(self): # pragma: no cover
if len(text) > 0:
file_mask = "FDF files (*.fdf);;VASP POSCAR file (*.POSCAR);;Crystal d12 (*.d12)"
file_mask += ";;PWscf in (*.in);;WIEN struct (*.struct);;CIF file (*.cif);;DFTB+ (*.gen)"
fname = self.get_file_name_from_save_dialog(file_mask)
if fname is not None:
helpers.write_text_to_file(fname, text)
file_mask += ";;Octopus input (*.in)"
f_name = self.get_file_name_from_save_dialog(file_mask)
if f_name is not None:
helpers.write_text_to_file(f_name, text)
except Exception as e:
self.show_error(e)

Expand Down Expand Up @@ -2931,14 +2942,24 @@ def lammps_to_form(self):
if len(self.models) == 0:
return
try:
text = "Not implemented"
model = self.models[self.active_model_id]
text = model_to_lammps_input(model)
if len(text) > 0:
self.ui.FormActionsPreTextFDF.setText(text)
except Exception as e:
self.show_error(e)

def octopus_to_form(self):
if len(self.models) == 0:
return
try:
model = self.models[self.active_model_id]
text = model_to_octopus_input(model)
if len(text) > 0:
self.ui.FormActionsPreTextFDF.setText(text)
except Exception as e:
self.show_error(e)

def dftb_0D_to_form(self):
if len(self.models) == 0:
return
Expand Down
108 changes: 62 additions & 46 deletions src/ui/form-v1.x.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1670,8 +1670,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<height>562</height>
<width>323</width>
<height>466</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -3658,8 +3658,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>361</width>
<height>405</height>
<width>371</width>
<height>562</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -4003,8 +4003,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>352</width>
<height>209</height>
<width>371</width>
<height>562</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -4232,13 +4232,22 @@
</item>
<item>
<widget class="QFrame" name="frame_53">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_48">
<property name="topMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_21">
<property name="orientation">
Expand All @@ -4253,12 +4262,45 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="FormModifyCellButton">
<widget class="QPushButton" name="modify_cell_cart_coord">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_81">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_124">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="modify_cell_frac_coord">
<property name="text">
<string>Edit (fractional)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
Expand Down Expand Up @@ -5929,59 +5971,20 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_131">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="crystal_2d_d12_generate">
<property name="text">
<string>2D</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_132">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="crystal_1d_d12_generate">
<property name="text">
<string>1D</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_81">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="crystal_0d_d12_generate">
<property name="text">
Expand Down Expand Up @@ -6027,6 +6030,12 @@
</item>
<item>
<widget class="QFrame" name="frame_29">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -6066,6 +6075,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="octopus_generate">
<property name="text">
<string>Octopus</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading

0 comments on commit 4c54c4d

Please sign in to comment.