From 4fe31b5826be9d6418ef305dbfaf9a84ab952913 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Mon, 10 Jul 2023 11:23:18 +0200
Subject: [PATCH] bugfix: setting an element wiped previsouly set attributes

SetElement sets default properties for mass and radius. Previously
set charge and anisou got wiped in the process. Charge and anisou
are now transferred and only mass and radius are reset.
---
 modules/mol/base/src/impl/atom_impl.hh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/modules/mol/base/src/impl/atom_impl.hh b/modules/mol/base/src/impl/atom_impl.hh
index c229a2d33..658184a42 100644
--- a/modules/mol/base/src/impl/atom_impl.hh
+++ b/modules/mol/base/src/impl/atom_impl.hh
@@ -116,7 +116,13 @@ public:
   { 
     if (element_!=ele) {
       element_=ele;
+      AtomProp* old_prop = prop_;
       prop_=impl::AtomProp::GetDefaultProps(element_);
+      if (old_prop && !old_prop->is_default) {
+        if(old_prop->has_anisou) this->SetAnisou(old_prop->anisou);
+        if(old_prop->charge != 0.0) this->SetCharge(old_prop->charge);
+        delete old_prop;
+      }
     }
   }
   bool HasDefaultProps() const { return prop_->is_default; }
-- 
GitLab