{"action":"created","issue":{"url":"https://api.github.com/repos/ParmEd/ParmEd/issues/827","repository_url":"https://api.github.com/repos/ParmEd/ParmEd","labels_url":"https://api.github.com/repos/ParmEd/ParmEd/issues/827/labels{/name}","comments_url":"https://api.github.com/repos/ParmEd/ParmEd/issues/827/comments","events_url":"https://api.github.com/repos/ParmEd/ParmEd/issues/827/events","html_url":"https://github.com/ParmEd/ParmEd/issues/827","id":203472768,"number":827,"title":"fix numbering in PDBs when negatives are actually used","user":{"login":"swails","id":779022,"avatar_url":"https://avatars.githubusercontent.com/u/779022?v=3","gravatar_id":"","url":"https://api.github.com/users/swails","html_url":"https://github.com/swails","followers_url":"https://api.github.com/users/swails/followers","following_url":"https://api.github.com/users/swails/following{/other_user}","gists_url":"https://api.github.com/users/swails/gists{/gist_id}","starred_url":"https://api.github.com/users/swails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swails/subscriptions","organizations_url":"https://api.github.com/users/swails/orgs","repos_url":"https://api.github.com/users/swails/repos","events_url":"https://api.github.com/users/swails/events{/privacy}","received_events_url":"https://api.github.com/users/swails/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-26T19:57:50Z","updated_at":"2017-01-26T19:59:40Z","closed_at":null,"body":"From @dacase:\r\n\r\nHi Jason:\r\n\r\nI can't remember if we addressed this before, but there is a problem\r\nin the PDBFile.write() method in pdb.py when the input residue numbers\r\nare negative or zero.  (I don't see a fix even in the gitub.com/amber-md\r\nversion.)\r\n\r\nExisting code around line 821:\r\n```python\r\n                    # Figure out the serial numbers we want to print\r\n                    if renumber:\r\n                        anum = (atom.idx + 1 + nmore)\r\n                        rnum = (res.idx + 1)\r\n                    else:\r\n                        anum = (pa.number or last_number + 1)\r\n                        rnum = (atom.residue.number or last_rnumber + 1)\r\n                    anum = anum - anum // 100000 * 100000\r\n                    rnum = rnum - rnum // 10000 * 10000\r\n```\r\nThis fails if renumber=False and atom.residue.number is < 1.  My suggestion:\r\n```python\r\n                    if renumber:\r\n                        anum = (atom.idx + 1 + nmore) % 100000\r\n                        rnum = (res.idx + 1) % 10000\r\n                    else:\r\n                        anum = pa.number\r\n                        rnum = atom.residue.number\r\n                        # optional--depends on where you think the atom\r\n                        #   and residue numbers originally came from:\r\n                        # This should prevent both positive and negative\r\n                        #   numbers from overflowing.  But would not be\r\n                        #   needed the the original values came from a\r\n                        #   load_file() operation.\r\n                        if anum > 0:\r\n                            anum = anum % 100000\r\n                        else\r\n                            anum = anum % 10000\r\n                        if rnum > 0:\r\n                            rnum = rnum % 10000\r\n                        else\r\n                            rnum = rnum % 1000\r\n```\r\nBasically, if renumber=False, you want to print out whatever was there\r\noriginally, not try to guess with things like last_rnumber+1 (which gives\r\nevery atom a different residue number if atom.residue.number=0).\r\n\r\nI've actually run across three PDB files recently that have negative or\r\nzero residue numbers; so this is rare but not unknown.\r\n\r\nApologies if I'm missing something here, or if there is some other\r\ninterpretation of renumber=False that is intended.\r\n\r\n...dac"},"comment":{"url":"https://api.github.com/repos/ParmEd/ParmEd/issues/comments/275496431","html_url":"https://github.com/ParmEd/ParmEd/issues/827#issuecomment-275496431","issue_url":"https://api.github.com/repos/ParmEd/ParmEd/issues/827","id":275496431,"user":{"login":"swails","id":779022,"avatar_url":"https://avatars.githubusercontent.com/u/779022?v=3","gravatar_id":"","url":"https://api.github.com/users/swails","html_url":"https://github.com/swails","followers_url":"https://api.github.com/users/swails/followers","following_url":"https://api.github.com/users/swails/following{/other_user}","gists_url":"https://api.github.com/users/swails/gists{/gist_id}","starred_url":"https://api.github.com/users/swails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swails/subscriptions","organizations_url":"https://api.github.com/users/swails/orgs","repos_url":"https://api.github.com/users/swails/repos","events_url":"https://api.github.com/users/swails/events{/privacy}","received_events_url":"https://api.github.com/users/swails/received_events","type":"User","site_admin":false},"created_at":"2017-01-26T19:59:39Z","updated_at":"2017-01-26T19:59:39Z","body":"I'll have to think about this -- the value -1 is used as a \"no atom number was assigned here\" (e.g., if you add atoms to a system or combine them or something), so my intent was to just increment (there's no \"right\" answer here).\r\n\r\nThis seems less common than actually *having* negative indexes though, so I should probably adopt the above suggestion."}}
{"actor":{"display_login":"swails"}}