-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Molecule class implementation #454
Comments
I think you are right, that we should be calling it
This is part of a broader discussion around how best to design the API for interacting with Blender objects. My thought process in implementing it this way, was to have the The idea behind wrapping them for the classes is for convenience and cleaned code, that calls the underlying generic way of interacting with Blender's API. It made sense to me when implementing it, but I am open to suggestions for changing it if you think it could be improved. mol.get_attribute('position')
# vs
mn.blender.obj.get_attribute(mol, 'position') There is also a separate discussion around naming for It was the best I could think of at the time, but I might switch them to
Some of these are leftovers of GitHub Copilot generated boilerplate that I didn't get around to cleaning up if I am being honest. I haven't really implemented anything that uses them - so it was on the todo list to clean up. You raise an important point that about how these methods should work (or if they are relevant) which also touches on discussions in other threads. Currently the My thoughts are that once we have everything inside of Blender we should pretty much just be interacting with the object, and we should just make sure we have pulled all relevant information from the file itself, with the option to 're-parse' the file for additional information if required for specific use cases. This is all very relevant to #359 so I am tagging it for cross-referencing |
I'm much more familiar with a functional style of programming - but I have tried to change the underlying workflow to utilise classes (this project is my first time doing so - so I welcome any and all suggestions for improving the implementations). I was unsure what to leave as a 'generic' function that could be used in multiple places and what should be class-associated methods. Certainly looking at it now, methods like |
There isn't much gained by the wrappers, especially when thinking about maintaining simple code. The code outline/flow currently stands as the These wrapper functions all return the same warning when the methods are called before the
Those names seem as good as any others. |
Yeah, the idea of the data twin to the blender object is maybe something that I implement outside of MN. Implementing the twin within the MN code so that 'truth' is consistent is a heavy lift for a generalizable addon. Conversely, recovering the abilities that pymol or VMD have require the use of structural biology libraries; its certainly not reasonable to expect MN to do those things natively. I actually don't think the "updating the truth" of two objects to be consistent is too hard. All you have to do is worry about coordinates and frame numbers (if a multiframe model). I don't think I'll need to worry about alterations made for keyframing the blender object's location/rotation/scaling; those are local changes that don't affect the vertex attributes. AFAIK, you can't keyframe changes to the internal vertex attributes. |
You're miles past me. I haven't messed around with Class objects until now. I think the Molecule class and its subclasses are the correct design for what they're doing. And I'm happy to help implement changes, if you'd like.
Yeah, that's true; the attribute functions could still be used within the method and all that. In a similar vein, could the fetch() and load() functions for wwpdb.py and local.py be implemented within the respective MN_OT_Import classes? Idk, that might be unnecessary. Why fix something that isn't broke? |
Operators in Blender aren't the best to work with via scripting, especially in a jupyter notebook or script. Because of this, I've designed it such that each import method is handled by one overarching function. This function can be called reliably from a script, and the operator that is executed when pressing a button just runs that one function with the necessary parameters. It adds an extra layer of abstraction, but I believe is necessary to have the operator and scripting interfaces be on par with each other. |
Here's some notes that I have for the current implementation of the Molecule class:
self.data
(see below), which is not an instantiated class variable in either the Molecule class nor the PDB, CIF, MMTF subclasses.https://github.com/rbdavid/MolecularNodes/blob/8f70f3195041b15b65da97ff60f1fa17258712d4/molecularnodes/io/parse/molecule.py#L337-L365
The
__len(self)__
method usesself.object.data.vertices
. This would be pulling the bpy.Object's data vertices values and taking the length. Maybe all of theself.data
instances should be usingself.object.data
as well?Additionally, the
__getitem__
method usesget_attribute(index)
, which is wrongly implemented for theMolecule.get_attribute()
defined on https://github.com/rbdavid/MolecularNodes/blob/8f70f3195041b15b65da97ff60f1fa17258712d4/molecularnodes/io/parse/molecule.py#L110-L133. Maybe this function was intended to get one atom's values for all attributes?Also, as noted in Centre upon import by either CoG or CoM #448 (comment), there are instances of
bpy.types.Object.mn()
lines that cause errors when I test the Molecule creation process on my local desktop.The
Molecule.get_attribute()
and similarset_attribute()
have the same name space as the functions defined inmolecularnodes/blender/obj.py
. The Molecule methods are just wrappers for those functions. This was actually quite confusing for me during coding up CoM/CoG methods because the Molecule methods will fail if called before settingself.object = model
within the `Molecule.create_model() method. I'm not sure if the Molecule methods are actually necessary since they are just wrapper functions for functions that act on a different object class all-together.This might be a variable naming issue but
frames
in theMolecule.create_model()
method is actually a bpy.types.Collection object rather than a list/iteratable of bpy.types.Objects. So maybe it should either be calledframe_collection
or be changed to a list of the blender objects within that collection.The text was updated successfully, but these errors were encountered: