Skip to content

Commit

Permalink
Forcefields list on Forcefields panel now displays original filename …
Browse files Browse the repository at this point in the history
…as tooltip. Made Forcefield plugin-aware. Updated forcefield editor so that it doesn't allow overwriting of Forcefields in anything other than Aten's own format.
  • Loading branch information
trisyoungs committed Dec 4, 2016
1 parent 239916d commit c501d03
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/ff/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Forcefield::Forcefield() : ListItem<Forcefield>()
{
// Private variables
energyUnit_ = Prefs::KiloJoules;
plugin_ = NULL;

// Create _NDEF_ type common to all FFs)
ForcefieldAtom* ffa = types_.add();
ffa->setParent(this);
Expand Down Expand Up @@ -83,6 +85,18 @@ QString Forcefield::filename()
return filename_;
}

// Sets the plugin used to load the Forcefield
void Forcefield::setPlugin(FilePluginInterface* plugin)
{
plugin_ = plugin;
}

// Return the plugin used to load the Forcefield
FilePluginInterface* Forcefield::plugin() const
{
return plugin_;
}

// Return internal energy unit of forcefield
Prefs::EnergyUnit Forcefield::energyUnit()
{
Expand Down
7 changes: 7 additions & 0 deletions src/ff/forcefield.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ATEN_BEGIN_NAMESPACE
class Atom;
class ForcefieldAtom;
class ForcefieldBound;
class FilePluginInterface;

// Forcefield
class Forcefield : public ListItem<Forcefield>
Expand All @@ -57,6 +58,8 @@ class Forcefield : public ListItem<Forcefield>
private:
// Title of Forcefield
QString name_;
// Plugin used to load / save the Forcefield (if any)
FilePluginInterface* plugin_;
// Filename
QString filename_;
// Energy unit of the forcefield parameters
Expand All @@ -71,6 +74,10 @@ class Forcefield : public ListItem<Forcefield>
void setFilename(QString filename);
// Return filename
QString filename();
// Sets the plugin used to load the Forcefield
void setPlugin(FilePluginInterface* plugin);
// Return the plugin used to load the Forcefield
FilePluginInterface* plugin() const;
// Return internal energy unit of forcefield
Prefs::EnergyUnit energyUnit();
// Set internal energy unit of forcefield
Expand Down
22 changes: 20 additions & 2 deletions src/gui/ffeditor_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gui/tintegerspindelegate.hui"
#include "ff/forcefield.h"
#include "model/model.h"
#include "plugins/interfaces/fileplugin.h"
#include "base/forcefieldatom.h"
#include "base/forcefieldbound.h"
#include "templates/variantpointer.h"
Expand Down Expand Up @@ -107,6 +108,9 @@ void AtenForcefieldEditor::populate(Forcefield* ff)
ui.FFEditorForcefieldLabel1->setText(ff->name());
ui.FFEditorForcefieldLabel2->setText(ff->filename());

// Save buttons
ui.SaveButton->setEnabled(ff->plugin() && ff->plugin()->name() == "Aten Forcefield Format");

// Types List
count = 0;
ui.FFEditorTypesTable->setRowCount(ff->nTypes()-1);
Expand Down Expand Up @@ -370,8 +374,8 @@ void AtenForcefieldEditor::boundFunctionChanged(QComboBox* sender, int i, Forcef
if (ffb->type() == ForcefieldBound::UreyBradleyInteraction) updateImpropersLabels(ffb);
else updateTorsionsLabels(ffb);
break;
default:
break;
default:
break;
}
}

Expand Down Expand Up @@ -454,6 +458,8 @@ void AtenForcefieldEditor::on_FFEditorTypesTable_itemChanged(QTableWidgetItem *w
case (TypeColumn::Description):
ffa->setDescription(qPrintable(w->text()));
break;
default:
break;
}
updating_ = false;
}
Expand Down Expand Up @@ -545,6 +551,8 @@ void AtenForcefieldEditor::on_FFEditorAtomsTable_itemChanged(QTableWidgetItem *w
n = column - AtomColumn::Data1;
ffa->setParameter(n, atof(qPrintable(w->text())));
break;
default:
break;
}
updating_ = false;
}
Expand Down Expand Up @@ -628,6 +636,8 @@ void AtenForcefieldEditor::on_FFEditorBondsTable_itemChanged(QTableWidgetItem *w
n = column - BondColumn::Data1;
ffb->setParameter(n, atof(qPrintable(w->text())));
break;
default:
break;
}
updating_ = false;
}
Expand Down Expand Up @@ -712,6 +722,8 @@ void AtenForcefieldEditor::on_FFEditorAnglesTable_itemChanged(QTableWidgetItem *
n = column - AngleColumn::Data1;
ffb->setParameter(n, atof(qPrintable(w->text())));
break;
default:
break;
}
updating_ = false;
}
Expand Down Expand Up @@ -805,6 +817,8 @@ void AtenForcefieldEditor::on_FFEditorTorsionsTable_itemChanged(QTableWidgetItem
n = column - TorsionColumn::Data1;
ffb->setParameter(n, atof(qPrintable(w->text())));
break;
default:
break;
}
updating_ = false;
}
Expand Down Expand Up @@ -884,6 +898,8 @@ void AtenForcefieldEditor::on_FFEditorImpropersTable_itemChanged(QTableWidgetIte
n = column - TorsionColumn::Data1;
ffb->setParameter(n, atof(qPrintable(w->text())));
break;
default:
break;
}
updating_ = false;
}
Expand Down Expand Up @@ -962,6 +978,8 @@ void AtenForcefieldEditor::on_FFEditorUreyBradleysTable_itemChanged(QTableWidget
n = column - AngleColumn::Data1;
ffb->setParameter(n, atof(qPrintable(w->text())));
break;
default:
break;
}
updating_ = false;
}
Expand Down
13 changes: 7 additions & 6 deletions src/gui/mainwindow_panel_forcefields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "gui/mainwindow.h"
#include "main/aten.h"
#include "ff/forcefield.h"
// #include "gui/selectfilter.h"
#include "gui/ffeditor.h"
#include <QFileDialog>

Expand All @@ -35,12 +34,14 @@ void AtenWindow::updateForcefieldsPanel(Model* sourceModel)

// Forcefields list
ui.ForcefieldsList->clear();
int n = 0;
for (Forcefield* ff = aten_.forcefields(); ff != NULL; ff = ff->next)
int count = 0;
for (Forcefield* ff = aten_.forcefields(); ff != NULL; ff = ff->next, ++count)
{
ui.ForcefieldsList->addItem(ff->name());
if (ff == aten_.currentForcefield()) ui.ForcefieldsList->setCurrentRow(n);
++n;
QListWidgetItem* item = new QListWidgetItem(ff->name());
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
item->setToolTip(QString("File: '%1'").arg(ff->filename()));
ui.ForcefieldsList->addItem(item);
if (ff == aten_.currentForcefield()) ui.ForcefieldsList->setCurrentRow(count);
}
ui.ForcefieldsManageRemoveButton->setEnabled(currentForcefield);
ui.ForcefieldsManageEditButton->setEnabled(currentForcefield);
Expand Down
2 changes: 1 addition & 1 deletion src/main/importexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Aten::processImportedObjects(FilePluginInterface* plugin, QString filename)

// Set source filename and plugin interface used
ff->setFilename(filename);
// ff->setPlugin(plugin);
ff->setPlugin(plugin);

// Pass the model pointer to Aten
ownForcefield(ff);
Expand Down

0 comments on commit c501d03

Please sign in to comment.