Skip to content

Commit

Permalink
Added export options dialog to PDB, allowing use of atom type names.
Browse files Browse the repository at this point in the history
  • Loading branch information
trisyoungs committed Jan 22, 2018
1 parent 002764a commit 59836dc
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/plugins/io_pdb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Meta-Objects
set(pdb_MOC_HDRS
pdb.hui
pdbexportoptions.h
pdbimportoptions.h
)
QT5_WRAP_CPP(pdb_MOC_SRCS ${pdb_MOC_HDRS} OPTIONS -I${PROJECT_SOURCE_DIR}/src)

SET(pdb_UIS
pdbexportoptions.ui
pdbimportoptions.ui
)
QT5_WRAP_UI(pdb_UIS_H ${pdb_UIS})

add_library(pdb MODULE
pdb_funcs.cpp
pdbexportoptions_funcs.cpp
pdbimportoptions_funcs.cpp
${pdb_MOC_SRCS}
${pdb_UIS_H}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/io_pdb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ clean-local:
-rm -f pdb.cpp

# AKF Model plugin
pdb_la_SOURCES = pdbimportoptions.ui pdbimportoptions_funcs.cpp pdb_funcs.cpp pdb.hui
pdb_la_SOURCES = pdbexportoptions.ui pdbexportoptions_funcs.cpp pdbimportoptions.ui pdbimportoptions_funcs.cpp pdb_funcs.cpp pdb.hui
pdb_la_LDFLAGS = -module -shared -avoid-version

noinst_HEADERS = pdbimportoptions.h
noinst_HEADERS = pdbexportoptions.h pdbimportoptions.h

AM_CPPFLAGS = -I${top_srcdir}/src @ATEN_INCLUDES@ @ATEN_CFLAGS@
28 changes: 23 additions & 5 deletions src/plugins/io_pdb/pdb_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include "plugins/io_pdb/pdb.hui"
#include "plugins/io_pdb/pdbexportoptions.h"
#include "plugins/io_pdb/pdbimportoptions.h"
#include "model/model.h"
#include "base/pattern.h"
Expand All @@ -33,6 +34,7 @@ PDBModelPlugin::PDBModelPlugin()

// Setup plugin options
pluginOptions_.add("strictFormat", "true");
pluginOptions_.add("useTypeNames", "false");
}

// Destructor
Expand Down Expand Up @@ -118,8 +120,10 @@ bool PDBModelPlugin::importData()
// Create default model
createModel("PDB Model");

// Get strict flag, and define strict formats
// Get options
bool strict = pluginOptions_.value("strictFormat") == "true";

// Define formats
ParseFormat generalFormat("%-6s%r");
ParseFormat crystFormat("%9f%9f%9f%7f%7f%7f");
ParseFormat atomFormat("%5i %4s %8f%8f%8f%22*%2s");
Expand Down Expand Up @@ -257,6 +261,9 @@ bool PDBModelPlugin::exportData()
int molId, n, m, bondCount;
QString s;

// Get plugin options
bool useTypeNames = pluginOptions_.value("useTypeNames") == "true";

if (!fileParser_.writeLine("REMARK Aten-created PDB")) return false;
if (!fileParser_.writeLine("TITLE " + targetModel()->name())) return false;

Expand All @@ -280,7 +287,9 @@ bool PDBModelPlugin::exportData()
{
for (n = 0; n < p->nAtoms(); ++n)
{
s = QString("%1%2").arg(ElementMap::symbol(i)).arg(n);
if (useTypeNames && i->type()) s = QString("%1%2").arg(i->type()->name()).arg(n);
else s = QString("%1%2").arg(ElementMap::symbol(i)).arg(n);

if (!fileParser_.writeLineF("ATOM %-5i %-4s MOL %-4i %8.3f%8.3f%8.3f%6.2f%6.2f %2s", i->id()+1, qPrintable(s), molId, i->r().x, i->r().y, i->r().z, 1.0, 1.0, ElementMap::symbol(i))) return false;
i = i->next;
}
Expand All @@ -289,7 +298,14 @@ bool PDBModelPlugin::exportData()
}
else for (i = targetModel()->atoms(); i != NULL; i = i->next)
{
if (!fileParser_.writeLineF("ATOM %-5i %-4s MOL %-4i %8.3f%8.3f%8.3f%6.2f%6.2f %2s", i->id()+1, ElementMap::symbol(i), molId, i->r().x, i->r().y, i->r().z, 1.0, 1.0, ElementMap::symbol(i))) return false;
if (useTypeNames && i->type())
{
if (!fileParser_.writeLineF("ATOM %-5i %-4s MOL %-4i %8.3f%8.3f%8.3f%6.2f%6.2f %2s", i->id()+1, qPrintable(i->type()->name()), molId, i->r().x, i->r().y, i->r().z, 1.0, 1.0, ElementMap::symbol(i))) return false;
}
else
{
if (!fileParser_.writeLineF("ATOM %-5i %-4s MOL %-4i %8.3f%8.3f%8.3f%6.2f%6.2f %2s", i->id()+1, ElementMap::symbol(i), molId, i->r().x, i->r().y, i->r().z, 1.0, 1.0, ElementMap::symbol(i))) return false;
}
}

// Loop over atoms and write bond information
Expand Down Expand Up @@ -365,12 +381,14 @@ bool PDBModelPlugin::showImportOptionsDialog(KVMap& targetOptions) const
// Return whether the plugin has export options
bool PDBModelPlugin::hasExportOptions() const
{
return false;
return true;
}

// Show export options dialog
bool PDBModelPlugin::showExportOptionsDialog(KVMap& targetOptions) const
{
return false;
PDBExportOptionsDialog optionsDialog(targetOptions);

return (optionsDialog.updateAndExecute() == QDialog::Accepted);
}

67 changes: 67 additions & 0 deletions src/plugins/io_pdb/pdbexportoptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*** PDB Export Options Dialog
*** src/plugins/io_pdb/pdbexportoptions.h
Copyright T. Youngs 2007-2017
This file is part of Aten.
Aten is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Aten is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Aten. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ATEN_PDBEXPORTOPTIONS_H
#define ATEN_PDBEXPORTOPTIONS_H

#include "base/kvmap.h"
#include "plugins/io_pdb/ui_pdbexportoptions.h"

ATEN_USING_NAMESPACE

// Forward Declarations (Aten)
/* none */

// PDB Export Options Dialog
class PDBExportOptionsDialog : public QDialog
{
// All Qt declarations derived from QObject must include this macro
Q_OBJECT

public:
// Constructor
PDBExportOptionsDialog(KVMap& pluginOptions);

private:
// Main form declaration
Ui::PDBExportOptionsDialog ui;
// Reference to KVMap of plugin options stored in plugin
KVMap& pluginOptions_;


/*
* Widget Functions
*/
private slots:
// Cancel / OK buttons
void on_CancelButton_clicked(bool checked);
void on_OKButton_clicked(bool checked);


/*
* Show Function
*/
public:
// Update and show dialog (setting controls from pluginOptions_ if necessary)
int updateAndExecute();
};

#endif
123 changes: 123 additions & 0 deletions src/plugins/io_pdb/pdbexportoptions.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PDBExportOptionsDialog</class>
<widget class="QDialog" name="PDBExportOptionsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>123</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="windowTitle">
<string>PDB Export Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QCheckBox" name="UseTypeNamesCheck">
<property name="toolTip">
<string>Write atom type names instead of element names in the atom records</string>
</property>
<property name="text">
<string>Use type names if available</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>362</width>
<height>48</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<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="CancelButton">
<property name="text">
<string>&amp;Cancel</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="OKButton">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>&amp;OK</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
60 changes: 60 additions & 0 deletions src/plugins/io_pdb/pdbexportoptions_funcs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
*** PDB Export Options Functions
*** src/gui/io_pdb/pdbexportoptions_funcs.cpp
Copyright T. Youngs 2007-2017
This file is part of Aten.
Aten is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Aten is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Aten. If not, see <http://www.gnu.org/licenses/>.
*/

#include "plugins/io_pdb/pdbexportoptions.h"

// Constructor
PDBExportOptionsDialog::PDBExportOptionsDialog(KVMap& pluginOptions) : QDialog(NULL), pluginOptions_(pluginOptions)
{
ui.setupUi(this);
}

/*
* Widget Functions
*/

void PDBExportOptionsDialog::on_CancelButton_clicked(bool checked)
{
// Don't modify the stored pluginOptions_, just reject() the dialog
reject();
}

void PDBExportOptionsDialog::on_OKButton_clicked(bool checked)
{
// Set options before we accept() the dialog.
pluginOptions_.add("useTypeNames", ui.UseTypeNamesCheck->isChecked() ? "true" : "false");

accept();
}

/*
* Show Function
*/

// Update and show dialog, setting controls from pluginOptions
int PDBExportOptionsDialog::updateAndExecute()
{
// Set controls to reflect current pluginOptions_
ui.UseTypeNamesCheck->setChecked(pluginOptions_.value("useTypeNames") == "true");

// Execute the dialog - option setting will be handled in the OK button slot
return exec();
}
2 changes: 1 addition & 1 deletion src/plugins/io_xyz/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ bool XYZFilePluginCommon::writeXYZModel(FilePluginInterface* plugin, FileParser&
}

return true;
}
}

0 comments on commit 59836dc

Please sign in to comment.