mosdef-hub / mbuild

A hierarchical, component based molecule builder
https://mbuild.mosdef.org
Other
171 stars 79 forks source link

Loss of meaningful port names and labels #1172

Closed jaclark5 closed 4 months ago

jaclark5 commented 5 months ago

Bug summary

Expect that upon flattening a Compound the labels will remain meaningful, and after removing atoms, labels will remain in order.

Code to reproduce the behavior

from mbuild.lib.moieties.peg import PegMonomer
from mbuild.lib.recipes.polymer import Polymer

Mon = PegMonomer()
print("Before", Mon.labels.keys())

Molecule = Polymer(monomers=Mon)
Molecule.build(1, add_hydrogens=True)
Molecule.flatten(inplace=True)
print("After Flatten", list(Molecule.labels.keys()))

# Remove Hydrogen Atoms
remove_array = []
for child in Molecule.children:
    if child.name == "H":
        remove_array.append(child)
Molecule.remove(remove_array)
print(list(Molecule.labels.keys()))
Before ['C', 'C[0]', 'H', 'H[0]', 'H[1]', 'C[1]', 'H[2]', 'H[3]', 'O', 'O[0]', 'down', 'up']
After Flatten ['monomer', 'H', 'Compound', 'Compound[0]', 'Compound[1]', 'Compound[2]', 'Compound[3]', 'Compound[4]', 'Compound[5]', 'Compound[6]', 'Compound[7]', 'Compound[8]']
After Remove H ['monomer', 'H', 'Compound', 'Compound[0]', 'Compound[3]', 'Compound[6]', 'port', 'port[1]', 'port[3]', 'port[5]', 'port[7]', 'port[9]', 'port[11]']

Software versions