From 4235fa9ff6ad35dcd85a16b38f55d5003d5fd860 Mon Sep 17 00:00:00 2001 From: Tristan Youngs Date: Thu, 1 Feb 2018 12:17:35 +0000 Subject: [PATCH] Extended FilePluginInterface to permit application of properly converted element names to atoms after their creation. Updated cif filter. --- src/plugins/interfaces/fileplugin.h | 21 +++++++++++++++++++++ src/plugins/io_cif/cif_funcs.cpp | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/plugins/interfaces/fileplugin.h b/src/plugins/interfaces/fileplugin.h index b1365a60d..cbb7fe90b 100644 --- a/src/plugins/interfaces/fileplugin.h +++ b/src/plugins/interfaces/fileplugin.h @@ -338,6 +338,27 @@ class FilePluginInterface : public BasePluginInterface return i; } + // Set element of specified Atom from supplied string, obeying current zmapping / conversion rules + int setAtomElement(Model* model, Atom* i, QString name) + { + // Find element in elements map + int el = ElementMap::find(name, standardOptions_.zMappingType() != ElementMap::nZMapTypes ? standardOptions_.zMappingType() : ElementMap::AutoZMap); + + // Set data in atom + i->setData(qPrintable(name)); + + // KeepNames and KeepTypes standard options + ForcefieldAtom* ffa = NULL; + if (standardOptions_.isSetAndOn(FilePluginStandardImportOptions::KeepNamesSwitch)) ffa = model->addAtomName(el, name); + else if (standardOptions_.isSetAndOn(FilePluginStandardImportOptions::KeepTypesSwitch)) ffa = ElementMap::forcefieldAtom(name); + if (ffa != NULL) + { + i->setType(ffa); + i->setTypeFixed(true); + } + + return el; + } // Clear any created data void clearCreatedData() { diff --git a/src/plugins/io_cif/cif_funcs.cpp b/src/plugins/io_cif/cif_funcs.cpp index e3511f53b..2a73be119 100644 --- a/src/plugins/io_cif/cif_funcs.cpp +++ b/src/plugins/io_cif/cif_funcs.cpp @@ -159,7 +159,7 @@ bool CIFModelPlugin::importData() case (CIFModelPlugin::AtomSiteTypeSymbol): case (CIFModelPlugin::AtomSiteLabel): case (CIFModelPlugin::ChemCompAtomTypeSymbol): - if (i->element() == 0) i->setElement(ElementMap::find(fileParser_.argc(n))); + if (i->element() == 0) setAtomElement(targetModel(), i, fileParser_.argc(n)); break; case (CIFModelPlugin::AtomSiteFractX): case (CIFModelPlugin::AtomSiteFractY):