.. _data_manipulation_intro:
===================================
Manipulating data
===================================
This chapter discusses how the contents of a :py:class:`~ovito.data.DataCollection` can be modified or amended from Python code, e.g., how
you can manipulate the values of particle properties or give particles additional properties. Please make sure to read the
:ref:`preceding section <data_model_intro>` first, which gives a description of how the data structures in a :py:class:`~ovito.data.DataCollection`
container are organized.
* :ref:`data_ownership`
* :ref:`underscore_notation`
* :ref:`creating_new_properties`
* :ref:`creating_new_bond_properties`
* :ref:`modifying_properties`
* :ref:`adding_global_attributes`
* :ref:`modifying_simulation_cell`
* :ref:`direct_modifier_application`
.. _data_ownership:
Data ownership
-----------------------------------
OVITO's data pipeline system tries to avoid unnecessary and expensive data copies as far as possible. In order to achieve this goal, data objects
follow a shared ownership model. That means they may be part of more than one :py:class:`~ovito.data.DataCollection` at the same time.
For instance, when you duplicate an existing :py:class:`~ovito.data.DataCollection` using its :py:meth:`~ovito.data.DataCollection.clone` method,
you will obtain a second data collection containing the exact same data objects as the original collection::
data2 = data.clone()
assert(data2.particles is data.particles)
The assertion statement above shows that the :py:class:`~ovito.data.Particles` object in the original data collection and in the cloned
collection are physically one and the same Python object. In other words, the :py:class:`~ovito.data.Particles` data object
has not been copied but rather just been inserted into the second data collection too. It is now owned simultaneously by both data collections.
This type of "shallow" copying is used by OVITO's data pipeline system in many situations. For instance, the :py:class:`~ovito.pipeline.FileSource`
of a pipeline always keeps the original :py:class:`~ovito.data.DataCollection` that was loaded from the input file in memory.
(You can access it through the :py:attr:`FileSource.data <ovito.pipeline.FileSource.data>` field.) This unmodified master copy of the
input data enables quick re-evaluations of the data pipeline in case a modifier is being changed, without the need to reload the input data
again from disk. Modifiers in the pipeline always operate on a copy of the original :py:class:`~ovito.data.DataCollection`, and it is
the final copy that the :py:meth:`Pipeline.compute() <ovito.pipeline.Pipeline.compute>` method returns to the caller. However,
it would be inefficient for the system to fully copy the master :py:class:`~ovito.data.DataCollection` including all its contents,
because modifiers typically change just a small portion of a dataset at a time, or they just amend the dataset with some newly computed information
without altering any of the existing data objects at all.
.. image:: graphics/shallow_copy_pipeline.*
:width: 90 %
:align: center
This is where so-called shallow object copies come into play. It is okay to share data objects between more than one data collection
as long as these data objects are not being modified. In case you intend to modify a particular data object, for example when implementing
a :ref:`user-defined modifier function <writing_custom_modifiers>`, you first have to make sure that the data object is exclusively owned
by just one :py:class:`~ovito.data.DataCollection`. Otherwise unwanted side effects would occur, because changing the data object in your
data collection would also affect the contents of another data collection owned by someone else.
.. note::
Data objects can be part of more than one data collection (or other type of container) at a time.
Then only read access to a shared data object is allowed, because object modifications would
result in unexpected side effects.
.. _underscore_notation:
Announcing object modification
------------------------------------
OVITO's Python programming interface has safeguards in place that prevent you from accidentally modifying data objects
that are shared with some other part of the program. Consider the following attempt to change
the boundary condition flags of a :py:class:`~ovito.data.SimulationCell` object in a data collection returned by the pipeline system::
>>> data = pipeline.compute()
>>> data.cell.pbc = (True, True, False)
RuntimeError: You tried to modify a SimulationCell object that is currently shared by
multiple owners. Please explicitly request a mutable version of the data object by
using the '_' notation.
The attempt to assign a new value to the cell's ``pbc`` field raised an error, because OVITO detects that the :py:class:`~ovito.data.SimulationCell`
object is not only part of the data collection returned by :py:meth:`Pipeline.compute() <ovito.pipeline.Pipeline.compute>` but
also of another internal data collection owned by the pipeline. Thus, modifying the simulation cell object is not valid, because
it would cause side effects on the internal state of OVITO.
The solution is to first make a unique copy of the :py:class:`~ovito.data.SimulationCell` object before modifying it. The programing
interface provides a handy shortcut notation for this::
>>> data.cell_.pbc = (True, True, False)
The underscore suffix appended to the :py:attr:`~ovito.data.DataCollection.cell` field signals the :py:class:`~ovito.data.DataCollection`
that your intention is to modify the simulation cell object. Behind the scenes, the data collection will check whether the cell object
is shared with multiple owners. If so, it will create an actual copy of the data object and replace the original reference in this data collection.
It thus makes sure that the returned :py:class:`~ovito.data.SimulationCell` object is exclusively owned by your data collection only, making it safe for you to modify it.
.. note::
Before modifying a data object that is referenced by multiple owners (i.e. that is part of more than one parent container),
the child object must be replaced with an exclusively owned copy of the original, which is safe to modify.
OVITO's Python interface provides the underscore notation to perform this copy-and-replacement step if needed.
You can consider the underscore suffix as a means to signal your intention to modify the object.
.. _creating_new_properties:
Assigning new particle properties
-----------------------------------------------------
New per-particle properties are assigned to a :ref:`particle system <particle_properties_intro>` using the :py:meth:`PropertyContainer.create_property() <ovito.data.PropertyContainer.create_property>`
method. In addition to the name of the property, this method accepts an optional NumPy array as argument
for initializing the per-particle values of the new property::
color_values = numpy.random.random_sample(size=(data.particles.count, 3))
data.particles_.create_property('Color', data=color_values)
Note that we used the underscore version of the :py:attr:`DataCollection.particles_ <ovito.data.DataCollection.particles>`
field here in order to request a modifiable version of the :py:class:`~ovito.data.Particles` container object.
This is necessary, because :py:meth:`~ovito.data.PropertyContainer.create_property` adds a new :py:class:`~ovito.data.Property`
object to the particles container object, which may be implicitly shared by multiple data collections (see previous section).
If the particle property with the given name already exists in the :py:class:`~ovito.data.Particles` container, then its contents will be overwritten
with the per-particle array provided in the NumPy array. For details, please see the documentation of the
:py:meth:`create_property() <ovito.data.PropertyContainer.create_property>` method.
.. _c
没有合适的资源?快使用搜索试试~ 我知道了~
ovito-basic-3.1.1-win64_lammps_lammps后处理_ovito后处理_ovito后处理_ovito
共561个文件
png:239个
html:182个
txt:31个
5星 · 超过95%的资源 6 下载量 81 浏览量
2021-10-04
11:20:27
上传
评论
收藏 45.52MB ZIP 举报
温馨提示
ovito软件是一个后处理软件,我用它来做lammps的简单后处理,
资源详情
资源评论
资源推荐
收起资源包目录
ovito-basic-3.1.1-win64_lammps_lammps后处理_ovito后处理_ovito后处理_ovito (561个子文件)
.buildinfo 234B
qt.conf 27B
rtd.css 30KB
basic.css 13KB
manual.css 5KB
classic.css 4KB
pygments.css 4KB
default.css 28B
avcodec-58.dll 12.28MB
Qt5Gui.dll 6.21MB
Qt5Core.dll 5.88MB
Qt5Widgets.dll 5.33MB
hdf5.dll 2.94MB
avfilter-7.dll 2.62MB
libcrypto-1_1-x64.dll 2.36MB
avformat-58.dll 1.89MB
qwindows.dll 1.4MB
Qt5Network.dll 1.27MB
ovito_qwt.dll 785KB
netcdf.dll 702KB
avutil-56.dll 644KB
swscale-5.dll 559KB
libssl-1_1-x64.dll 505KB
ssh.dll 473KB
Qt5DBus.dll 432KB
qjpeg.dll 394KB
Qt5Svg.dll 331KB
Qt5PrintSupport.dll 317KB
swresample-3.dll 210KB
Qt5Xml.dll 192KB
qwindowsvistastyle.dll 140KB
hdf5_hl.dll 113KB
zlib.dll 83KB
qsvgicon.dll 40KB
qgif.dll 37KB
Qt5Concurrent.dll 33KB
ovito_modifiers.doctree 1.12MB
ovito_data.doctree 599KB
ovito_vis.doctree 432KB
ovito_pipeline.doctree 128KB
ovito_io.doctree 80KB
data_manipulation.doctree 70KB
version_changes.doctree 69KB
data_model.doctree 61KB
overview.doctree 59KB
custom_modifiers.doctree 51KB
file_io.doctree 46KB
running.doctree 43KB
pipelines.doctree 31KB
rendering.doctree 30KB
ovito.doctree 30KB
advanced_topics.doctree 22KB
ovito_io_ase.doctree 19KB
order_parameter_calculation.doctree 14KB
voronoi_indices.doctree 12KB
cna_bond_indices.doctree 12KB
msd_calculation.doctree 11KB
visualize_local_lattice_orientation.doctree 10KB
examples.doctree 9KB
creating_particles.doctree 9KB
select_overlapping_particles.doctree 9KB
data_plot.doctree 8KB
highlight_particle.doctree 7KB
scale_bar.doctree 6KB
index.doctree 4KB
ovito.exe 8.35MB
trajectory_lines_example.gif 1.18MB
flow_trajectory_example.gif 807KB
shear_marker.gif 422KB
ovito_modifiers.html 496KB
ovito_data.html 274KB
ovito_vis.html 179KB
genindex.html 94KB
ovito_pipeline.html 64KB
particles.modifiers.polyhedral_template_matching.html 45KB
data_manipulation.html 41KB
version_changes.html 41KB
particles.modifiers.dislocation_analysis.html 41KB
ovito_io.html 41KB
appendix.GPL.html 38KB
overview.html 36KB
data_model.html 34KB
custom_modifiers.html 31KB
file_io.html 29KB
particles.modifiers.atomic_strain.html 26KB
rendering.html 25KB
particles.modifiers.compute_property.html 24KB
pipelines.html 23KB
appendix.GFDL.html 23KB
running.html 22KB
particles.modifiers.construct_surface_mesh.html 22KB
particles.modifiers.html 19KB
cna_bond_indices.html 18KB
ovito.html 17KB
highlight_particle.html 17KB
order_parameter_calculation.html 17KB
visualize_local_lattice_orientation.html 17KB
creating_particles.html 17KB
advanced_topics.html 16KB
particles.modifiers.wigner_seitz_analysis.html 16KB
共 561 条
- 1
- 2
- 3
- 4
- 5
- 6
鹰忍
- 粉丝: 64
- 资源: 4707
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论13