BioStructures.jl icon indicating copy to clipboard operation
BioStructures.jl copied to clipboard

Suggestion: Make structural elements mutable

Open amaurypm opened this issue 5 years ago • 7 comments

I just was trying to use BioStructures to solve a problem which required making copies of chains, rename them, alter atom serial numbers and other modifications to structural elements. In its current implementation only the atom coordinates can be modified. This package is great, but I think it could be much more useful if the corresponding structures are declared as mutable, and I don't see any downside on doing that. It would be great to be able to modify atoms, residues and chains and create new models/structures with them. Best regards, Amaury

amaurypm avatar Jul 02 '20 17:07 amaurypm

Thanks for trying out the package. I agree that mutable elements would be great. Sadly, it's a little more complex than adding mutable in front of struct. Firstly, you lose some speed, though I don't know how much. I could benchmark that quite easily actually.

More importantly though, you can't just change properties directly and expect the parent/child relationships to work. For example, if you relabel a chain you would need to modify the chain dictionary in the parent model.

I think the right way to do it would be to have setters (chainid! etc.) that create the relevant new immutable objects, modify existing objects as required, and throw errors when a name clash is found. That has been on the todo list for a while but it is a fair amount of work, and I'll admit I didn't have so much use for it myself. If I was writing the package from scratch I would build this in from the start and it would probably be easier.

The lowest-hanging fruit would be to do chainid! as an example and see how it goes. I might have a go at some point.

jgreener64 avatar Jul 02 '20 17:07 jgreener64

Thank you for your response. I suspected it won't be so easy as making the structures mutable, and I was thinking in setters, as you explained. I guess for now I'll try to implement the creation of new elements from existing ones in my code, copying what I want to preserve and modifying the rest.

amaurypm avatar Jul 02 '20 18:07 amaurypm

Someone else asked about this on Discourse: https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211

Making the structs mutable doesn't actually lose any speed, so I'll try and get some setters coded.

jgreener64 avatar Nov 16 '20 14:11 jgreener64

I have the same use case as @amaurypm and have ended up here after going down the same route that he has. Do you want some help on this?

gusennan avatar Sep 30 '21 14:09 gusennan

That would be great, I haven't had time myself. I am happy to help and to review PRs, I would recommend seeing how chainid! goes first.

jgreener64 avatar Sep 30 '21 14:09 jgreener64

That would be great, I haven't had time myself. I am happy to help and to review PRs, I would recommend seeing how chainid! goes first.

I took a stab at it. It was a bit more complicated than I thought it would be :)

gusennan avatar Oct 21 '21 19:10 gusennan

Thanks to @gusennan the chainid! function is available as of v1.1.0.

jgreener64 avatar Nov 26 '21 19:11 jgreener64