Forum Navigation
You need to log in to create posts and topics.

Adding atoms to Particles() object

Dear developers,

is there a convenient way to combine several Particles() objects into one?

I try to modify the structure by functionalizing the surface. Ideally, I would like to create a new Particles() object with my new atoms programmatically and then merge it into the main Particles() object. Something similar to Combine Datasets (but without a dataset), but without an external file.

If I get it correctly, there're two ways to go here: either to modify the existing Particles() objects or to write a merge-function as a user-modifier. Both ways are prone to errors, especially the second one.

I would be happy to know the best way here. Thank you in advance!

Best regards,



Hi Arkadii,

Yes, this can be accomplished in a straightforward manner. Let's assume you have two Particles objects: particles1 and particles2. They can be merged into a single object using the CombineDatasetsModifier:

data1 = DataCollection(objects = [particles1])
data2 = DataCollection(objects = [particles2])
data1.apply(CombineDatasetsModifier(source = StaticSource(data = data2)))    
combined_particles = data1.particles

Each Particles objects needs to be first inserted into a DataCollection (unless, of course, you already have a DataCollection containing the particles to begin with). Then the CombineDatasetsModifier can be applied in place to the first data collection. The second data collection needs to be turned into a data source by creating a temporary StaticSource instance.