Dear ChimeraX Users,

I am trying to perform a morphing between two cryo-EM structures of the same complex, where one structure has twice the number of chains as the other (PDBs 3J9K and 8Y6Q). However, the larger structure causes an error during morphing.

I have attempted to write a script that aligns the two structures and deletes the unmatched chains from the larger structure. Unfortunately, the script is not working as expected.


from chimerax.core.commands import run

def delete_unmatched_chains(session):
# Get models #1 and #2
m1 = next((m for m in session.models if m.id == (1,)), None)
m2 = next((m for m in session.models if m.id == (2,)), None)

if m1 is None or m2 is None:
session.logger.info("Model #1 or #2 not found.")
return

chains1 = {chain.chain_id for chain in m1.chains}
chains2 = {chain.chain_id for chain in m2.chains}

unmatched = chains1 - chains2

if unmatched:
chain_ids = ",".join(unmatched)
# Deleting unmatched chains
run(session, f"delete /{chain_ids}")
session.logger.info(f"Deleted chains: {', '.join(unmatched)}")
else:
session.logger.info("No unmatched chains found.")




Could you please help me or alternatively propose another solution? Any suggestions would be greatly appreciated.

Thank you in advance !


Enrico