{"action":"created","issue":{"url":"https://api.github.com/repos/pierrepo/PBxplore/issues/115","repository_url":"https://api.github.com/repos/pierrepo/PBxplore","labels_url":"https://api.github.com/repos/pierrepo/PBxplore/issues/115/labels{/name}","comments_url":"https://api.github.com/repos/pierrepo/PBxplore/issues/115/comments","events_url":"https://api.github.com/repos/pierrepo/PBxplore/issues/115/events","html_url":"https://github.com/pierrepo/PBxplore/pull/115","id":144628548,"number":115,"title":"[Proposal] Optimize PBassign when reading xtc trajectory","user":{"login":"HubLot","id":1273176,"avatar_url":"https://avatars.githubusercontent.com/u/1273176?v=3","gravatar_id":"","url":"https://api.github.com/users/HubLot","html_url":"https://github.com/HubLot","followers_url":"https://api.github.com/users/HubLot/followers","following_url":"https://api.github.com/users/HubLot/following{/other_user}","gists_url":"https://api.github.com/users/HubLot/gists{/gist_id}","starred_url":"https://api.github.com/users/HubLot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HubLot/subscriptions","organizations_url":"https://api.github.com/users/HubLot/orgs","repos_url":"https://api.github.com/users/HubLot/repos","events_url":"https://api.github.com/users/HubLot/events{/privacy}","received_events_url":"https://api.github.com/users/HubLot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-30T15:28:53Z","updated_at":"2016-03-30T16:30:18Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pierrepo/PBxplore/pulls/115","html_url":"https://github.com/pierrepo/PBxplore/pull/115","diff_url":"https://github.com/pierrepo/PBxplore/pull/115.diff","patch_url":"https://github.com/pierrepo/PBxplore/pull/115.patch"},"body":"Hi,\r\n\r\nI continue my quest of optimize PBxplore. In this PR, I focused mainly on the reading of xtc trajectory through MDAnalysis and I was able to gain ~15% speed-up.\r\n\r\nFirst, I introduced [classmethod property](https://docs.python.org/2/library/functions.html#classmethod) for the class `Atom`. I noticed we usually create an empty `Atom()` and then populate it with values depending on the input (PDB, PDBx, XTC). Creating an empty object and then modify its attributes is not really efficient. \r\n`@classmethod` allow us to redefine a function to be a constructor. Create a object and set its attribute is now done once.\r\n\r\nFor example:\r\n`atom = Atom(); atom.read_PDB(line)`\r\nis now\r\n`atom = Atom.read_PDB(line)`\r\n\r\nI also removed some `Atom()` attributes which were never used (occupancy, temperature, etc). This does not change the output of `format()` function.\r\nI also realized that:\r\n```\r\nself.x, self.y, self.z = atm.position\r\n```\r\nis faster than\r\n```\r\nself.x = atm.position[0]\r\nself.y = atm.position[1]\r\nself.z = atm.position[2]\r\n```\r\n\r\nSecond, I focused on the `chains_from_trajectory()` function. I noticed, at each frame, we created a new `chain` object (called `structure`) filled with new atoms while in fact, only the coordinates of these atoms changed during a trajectory. It was a bit overkill :)\r\nNow, only one `structure` object is created at the beginning. During the loop over the trajectory, only the coordinates of the atoms are updated. To do that, I introduced some new functions inside `Atom()` (a setter to modify the coordinates) and `Chain()` ( a function which modify all coordinates of all atoms).\r\nWith these optimizations, the  `chains_from_trajectory()` function cannot be faster unless touching MDAnalysis. Creating the universe object and looping over the trajectory take now 95% of the time of this function whereas it was ~50% before.\r\n\r\nEventually, all of these optimizations don't change the public API.\r\n\r\nLet me know what you think!\r\n\r\nP.S: I fixed an issue with the doc build and remove some weird print() (my fault) in tests."},"comment":{"url":"https://api.github.com/repos/pierrepo/PBxplore/issues/comments/203514092","html_url":"https://github.com/pierrepo/PBxplore/pull/115#issuecomment-203514092","issue_url":"https://api.github.com/repos/pierrepo/PBxplore/issues/115","id":203514092,"user":{"login":"pierrepo","id":733861,"avatar_url":"https://avatars.githubusercontent.com/u/733861?v=3","gravatar_id":"","url":"https://api.github.com/users/pierrepo","html_url":"https://github.com/pierrepo","followers_url":"https://api.github.com/users/pierrepo/followers","following_url":"https://api.github.com/users/pierrepo/following{/other_user}","gists_url":"https://api.github.com/users/pierrepo/gists{/gist_id}","starred_url":"https://api.github.com/users/pierrepo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pierrepo/subscriptions","organizations_url":"https://api.github.com/users/pierrepo/orgs","repos_url":"https://api.github.com/users/pierrepo/repos","events_url":"https://api.github.com/users/pierrepo/events{/privacy}","received_events_url":"https://api.github.com/users/pierrepo/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T16:30:18Z","updated_at":"2016-03-30T16:30:18Z","body":"Not so simple the use of decorator.... But why not."}}