Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add Forcefield Wizard Update (#1629) #1860

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
28 changes: 12 additions & 16 deletions src/gui/models/addForcefieldDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void AddForcefieldDialogModel::next()
Q_EMIT assignErrors({});
break;
case AddForcefieldDialogModel::Page::AtomTypesPage:
if (!ff_) // No valud forcefield
// Must have a valid forcefield
if (!ff_)
return;
modifiedSpecies_ = temporaryDissolve_->coreData().addSpecies();
modifiedSpecies_->copyBasic(species_);
Expand Down Expand Up @@ -104,6 +105,7 @@ void AddForcefieldDialogModel::next()
index_ = AddForcefieldDialogModel::Page::IntramolecularPage;
break;
case AddForcefieldDialogModel::Page::IntramolecularPage:
assignIntramolecularTerms(ff_);
Q_EMIT mastersChanged();
index_ = AddForcefieldDialogModel::Page::MasterTermsPage;
break;
Expand All @@ -122,8 +124,6 @@ void AddForcefieldDialogModel::setDissolve(Dissolve &dissolve)
dissolve_ = &dissolve;

temporaryDissolve_ = std::make_unique<Dissolve>(temporaryCoreData_);
auto node = dissolve_->coreData().serialiseMaster();
temporaryCoreData_.deserialiseMaster(node);
masters_ = std::make_unique<MasterTermTreeModel>();
masters_->setData(temporaryCoreData_.masterBonds(), temporaryCoreData_.masterAngles(), temporaryCoreData_.masterTorsions(),
temporaryCoreData_.masterImpropers());
Expand Down Expand Up @@ -247,9 +247,6 @@ void AddForcefieldDialogModel::finalise()
original.setCharge(modified.charge());
}

// Assign intramolecular terms if we need to
assignIntramolecularTerms(ff_);

// Copy intramolecular terms
if (intramolecularRadio_ != Radio::None)
{
Expand Down Expand Up @@ -333,16 +330,16 @@ void AddForcefieldDialogModel::addMasterSuffix(int type, int index, QString suff
switch (type)
{
case 0:
termData = masters_->bondModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->bondModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
case 1:
termData = masters_->angleModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->angleModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
case 2:
termData = masters_->torsionModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->torsionModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
case 3:
termData = masters_->improperModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->improperModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
};
}
Expand All @@ -369,16 +366,16 @@ void AddForcefieldDialogModel::addMasterPrefix(int type, int index, QString pref
switch (type)
{
case 0:
termData = masters_->bondModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->bondModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
case 1:
termData = masters_->angleModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->angleModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
case 2:
termData = masters_->torsionModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->torsionModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
case 3:
termData = masters_->improperModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
masters_->improperModel_.setTermData(index, MasterTermModelData::DataType::Name, newName);
break;
};
}
Expand Down Expand Up @@ -411,13 +408,12 @@ void AddForcefieldDialogModel::assignIntramolecularTerms(const Forcefield *ff)
if (intramolecularRadio_ == Radio::Selected)
flags += Forcefield::SelectionOnlyFlag;

// Try to assign terms across the species
if (!ff->assignIntramolecular(modifiedSpecies_, flags))
// Assigning failed
return;

// Reduce to master terms?
if (!noMasterTerms_)
modifiedSpecies_->reduceToMasterTerms(temporaryCoreData_, intramolecularRadio_ == Radio::Selected);
}
return;
}
2 changes: 1 addition & 1 deletion src/gui/models/masterTermModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ QVariant MasterTermModel::data(const QModelIndex &index, int role) const
if (role == MasterTermModelData::Roles::Icon && iconFunction_)
return QIcon(iconFunction_(getTermData(index.row(), MasterTermModelData::DataType::Name).toString().toStdString())
? ":/general/icons/warn.svg"
: ":/general/icons/warn.svg");
: ":/general/icons/true.svg");

if (role == MasterTermModelData::Roles::Display || role == MasterTermModelData::Roles::Edit)
return getTermData(index.row(), static_cast<MasterTermModelData::DataType>(index.column()));
Expand Down
8 changes: 4 additions & 4 deletions src/gui/models/masterTermTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ void MasterTermTreeModel::setData(std::vector<std::shared_ptr<MasterBond>> &bond

void MasterTermTreeModel::setBondIconFunction(std::function<bool(std::string_view termName)> func)
{
bondModel_.setIconFunction(func);
bondModel_.setIconFunction(std::move(func));
}

void MasterTermTreeModel::setAngleIconFunction(std::function<bool(std::string_view termName)> func)
{
angleModel_.setIconFunction(func);
angleModel_.setIconFunction(std::move(func));
}

void MasterTermTreeModel::setTorsionIconFunction(std::function<bool(std::string_view termName)> func)
{
torsionModel_.setIconFunction(func);
torsionModel_.setIconFunction(std::move(func));
}

void MasterTermTreeModel::setImproperIconFunction(std::function<bool(std::string_view termName)> func)
{
improperModel_.setIconFunction(func);
improperModel_.setIconFunction(std::move(func));
}

void MasterTermTreeModel::prefixNames(QList<QModelIndex> indices, QString prefix)
Expand Down
1 change: 1 addition & 0 deletions src/gui/qml/AddForcefieldTermsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Page {
font.pointSize: 10
palette.buttonText: palette.active.text
palette.disabled.buttonText: palette.disabled.text
spacing: 4
visible: true

AddForcefieldDialogModel {
Expand Down
1 change: 1 addition & 0 deletions src/gui/qml/IconListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ListView {
anchors.bottom: label.bottom
anchors.left: parent.left
anchors.top: label.top
height: 10
source: icon ? "qrc:/general/icons/warn.svg" : "qrc:/general/icons/true.svg"
width: height
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qml/ImageRadio.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ RadioButton {
id: icon
anchors.left: padding.right
fillMode: Image.PreserveAspectFit
height: instructions.height
height: width
opacity: control.enabled ? 1.0 : 0.3
source: control.source
width: 16
}
D.Text {
id: instructions
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qml/widgets/Text.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import QtQuick

Text {
anchors.margins: 4
font.pointSize: 11
font.pointSize: 10
wrapMode: Text.Wrap
}