CombineDatasetsModifier causes program to crash
Dear Alex,
The bug: When trying to merge two DataCollection objects, the CombineDataSetsModifier crashes OVITO, if the first DataCollection doesn't contain the Bonds container in the Particles object, but the second one does.
Expected behavior: Bonds container is created automatically or the Particles objects are merged without any bonds.
Thanks, Arkadii
How to reproduce (build 601):
from ovito.data import *
from ovito.modifiers import CombineDatasetsModifier
from ovito.pipeline import StaticSource
# Create the main data collection containing a Particles object:
particles = Particles()
data_main = DataCollection()
data_main.objects.append(particles)
# XYZ coordinates of the atom to create:
pos = [(5.0, 9.2, 8.0)]
# Create the particle position property:
pos_prop = particles.create_property('Position', data=pos)
# Create the particle type property and insert an atom types:
type_prop = particles.create_property('Particle Type')
type_prop.types.append(ParticleType(id = 2, name = 'Ni', color = (0.0,0.5,1.0)))
type_prop[0] = 2 # Atom is Ni
# Create the simulation box:
cell = SimulationCell(pbc = (False, False, False))
cell[...] = [[10,0,0,0],
[0,10,0,0],
[0,0,10,0]]
cell.vis.line_width = 0.1
data_main.objects.append(cell)
# particles.bonds = Bonds() #BUG If no Bonds container is available in the main object, but there're bonds in the auxillary object, the program terminates unexpectedly
# Expected behavior: Bonds countainer is created automatically or the Particles objects are merged without any bonds
# Create the auxilary data collection containing a Particles object:
particles = Particles()
data_aux = DataCollection()
data_aux.objects.append(particles)
# XYZ coordinates of the atoms to create:
pos = [(1.0, 1.5, 0.3),
(7.0, 4.2, 6.0)]
# Create the particle position property:
pos_prop = particles.create_property('Position', data=pos)
# Create the particle type property and insert two atom types:
type_prop = particles.create_property('Particle Type')
type_prop.types.append(ParticleType(id = 1, name = 'Cu', color = (0.0,1.0,0.0)))
type_prop.types.append(ParticleType(id = 2, name = 'Ni', color = (0.0,0.5,1.0)))
type_prop[0] = 1 # First atom is Cu
type_prop[1] = 2 # Second atom is Ni
# Create a bond between atoms:
bond_topology = [[0,1]]
particles.bonds = Bonds()
particles.bonds.create_property('Topology', data=bond_topology)
data_main.apply(CombineDatasetsModifier(source = StaticSource(data = data_aux)))
Backtrace (build 592), but the behavior is indentical in 601:
Thread 1 "ovito" received signal SIGSEGV, Segmentation fault.
0x00007ffff69c9d6e in Ovito::DataObject::makeMutable(Ovito::DataObject const*) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
(gdb) bt
#0 0x00007ffff69c9d6e in Ovito::DataObject::makeMutable(Ovito::DataObject const*) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#1 0x00007fffeafc49dd in Ovito::Particles::ParticlesCombineDatasetsModifierDelegate::apply(Ovito::Modifier*, Ovito::PipelineFlowState&, int, Ovito::ModifierApplication*, std::vector<std::reference_wrapper<Ovito::PipelineFlowState const>, std::allocator<std::reference_wrapper<Ovito::PipelineFlowState const> > > const&) () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/Particles.so
#2 0x00007ffff69e3fae in Ovito::MultiDelegatingModifier::applyDelegates(Ovito::PipelineFlowState&, int, Ovito::ModifierApplication*, std::vector<std::reference_wrapper<Ovito::PipelineFlowState const>, std::allocator<std::reference_wrapper<Ovito::PipelineFlowState const> > > const&)
() from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#3 0x00007fffea40f86c in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/StdMod.so
#4 0x00007fffea40fc29 in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/StdMod.so
#5 0x00007fffea41052b in Ovito::StdMod::CombineDatasetsModifier::evaluate(int, Ovito::ModifierApplication*, Ovito::PipelineFlowState const&)
() from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/StdMod.so
#6 0x00007ffff69dc551 in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#7 0x00007ffff69dda5d in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#8 0x00007ffff69ddf0d in Ovito::ModifierApplication::evaluateInternal(int, bool) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#9 0x00007ffff69d4d12 in Ovito::CachingPipelineObject::evaluate(int, bool) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#10 0x00007fffe341084e in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/PyScript.so
#11 0x00007fffe33c8ce6 in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/PyScript.so
#12 0x00007fffe2f117e3 in _PyMethodDef_RawFastCallKeywords () at Objects/call.c:694
#13 0x00007fffe2f11570 in _PyCFunction_FastCallKeywords (func=0x7fffcb59f820, args=<optimized out>, nargs=<optimized out>,
kwnames=<optimized out>) at Objects/call.c:734
#14 0x00007fffe2f9b511 in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>) at Python/ceval.c:4619
#15 _PyEval_EvalFrameDefault () at Python/ceval.c:3093
#16 0x00007fffe2f956c1 in _PyEval_EvalCodeWithName () at Python/ceval.c:3930
#17 0x00007fffe2f12821 in _PyFunction_FastCallKeywords () at Objects/call.c:433
#18 0x00007fffe2f968cc in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>) at Python/ceval.c:4616
#19 _PyEval_EvalFrameDefault () at Python/ceval.c:3110
#20 0x00007fffe2f12d3a in function_code_fastcall (globals=<optimized out>, nargs=2, args=<optimized out>, co=0x7fff95b72780)
at Objects/call.c:283
#21 _PyFunction_FastCallDict () at Objects/call.c:322
#22 0x00007fffe34704de in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/PyScript.so
#23 0x00007fffe33ba0f9 in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/PyScript.so
#24 0x00007fffe33bb376 in PyScript::ScriptEngine::executeSync(Ovito::RefTarget*, std::shared_ptr<Ovito::Task> const&, char const*, std::function<void ()> const&) () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/PyScript.so
#25 0x00007fffe33bc012 in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/lib/ovito/plugins/PyScript.so
#26 0x00007ffff5524259 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/libQt5Core.so.5
#27 0x00007ffff557c1c3 in ?? () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/libQt5Core.so.5
#28 0x00007ffff17f9417 in g_main_context_dispatch () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
---Type <return> to continue, or q <return> to quit---
#29 0x00007ffff17f9650 in ?? () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#30 0x00007ffff17f96dc in g_main_context_iteration () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#31 0x00007ffff557b7df in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/libQt5Core.so.5
#32 0x00007ffff552008a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/libQt5Core.so.5
#33 0x00007ffff5528b80 in QCoreApplication::exec() () from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/libQt5Core.so.5
#34 0x00007ffff69762df in Ovito::StandaloneApplication::runApplication() ()
from /home/arkadii/OVITO/ovito-3.0.0-dev592-x86_64/bin/../lib/ovito/plugins/Core.so
#35 0x000000000040177d in main ()
EDIT: A short follow-up: Without any topology defined in the first object, the atomic indices in the bonds are incorrect after merging. I used the following workaround, it's not a nice looking one, though:
particles.bonds.create_property('Topology', data = [[0,0]])