Skip to content
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

Set b-factor for PDB file #1359

Closed
xiki-tempula opened this issue May 22, 2017 · 11 comments
Closed

Set b-factor for PDB file #1359

xiki-tempula opened this issue May 22, 2017 · 11 comments

Comments

@xiki-tempula
Copy link
Contributor

xiki-tempula commented May 22, 2017

Expected behaviour

I have a pdb file which I want to set b-factors to the atoms.

Actual behaviour

The b-factor field in the pdb file is not changed

Code to reproduce the behaviour

from MDAnalysis import Universe
from six import StringIO

pdb = 'ATOM      1  N   MET S   1      85.260  60.210  43.770  1.00  0.00      SYST N'
u = Universe(StringIO(pdb), format='pdb')
u.atoms.bfactors = 0.5
u.atoms.write('test.pdb')

The content of test.pdb:

HEADER
TITLE MDANALYSIS FRAME 0: Created by PDBWriter
CRYST1 0.000 0.000 0.000 0.00 0.00 0.00 P 1 1
ATOM 1 N MET S 1 85.260 60.210 43.770 1.00 0.00 SYST N
END

Currently version of MDAnalysis:

py35, mda0.16.1

@kain88-de
Copy link
Member

See #1092 . The problem is that the bfactors aren't in the original topology and this needs to be updated not the atomgroup you selected there.

We are working on it. There should also be a PR from @richardjgowers that fixes this. Some comments on the UI/API would be nice.

@orbeckst
Copy link
Member

I am going to re-open this one, even though it is a duplicate of #1092 because

  1. it is a common use case and anyone being bitten by the new topology system should be able to find this as an open issue
  2. it breaks the official MDAnalysis tutorial Example: Saving dynamic per-atom properties in B-factor (which admittedly needs an overhaul...).
  3. it used to to work... so it's a regression

@orbeckst
Copy link
Member

orbeckst commented Aug 5, 2017

Note: at the moment you have to do manually add the tempfactors topology attribute

u.add_TopologyAttr(MDAnalysis.core.topologyattrs.Tempfactors(np.zeros(len(u.atoms))))

u.atoms.tempfactors = 0.5
u.atoms.write("withbfacs.pdb")

@orbeckst
Copy link
Member

We might not do much more here than properly document it. Opinions?

@richardjgowers
Copy link
Member

@orbeckst I think it is possible to make this behaviour work, I (or someone else) just needs to get the hacking done under the hood. Short term documenting it is definitely a good thing though.

@weiHelloWorld
Copy link

@orbeckst Just curious why "b-factor" is renamed "tempfactor" in the new version?

@orbeckst
Copy link
Member

orbeckst commented Sep 29, 2017

tempFactor is the offical name in the ATOM record of the PDB format. We don't like camelCase so we use tempfactor. We also use the convention that "arrays" are plural words, hence tempfactors.

The new usage is incompatible with previous versions of MDAnalysis where you could do things like atoms.set_bfactors. But that was a specialized hack. The new system is universal and fully internally consistent so it was worth breaking the old behavior but of course we know that it is always a hassle for users – sorry!

EDIT: And I think we didn't mind renaming bfactors -> tempfactors because we were breaking everything anyway so we opted to go with the "proper" PDB name.

@weiHelloWorld
Copy link

I see, thank you!

@orbeckst
Copy link
Member

This should work now with #1092 and is also documented under Universe.add_TopologyAttr.

@orbeckst
Copy link
Member

@weiHelloWorld – just fyi, we added bfactors back... see the example that I linked above.

@weiHelloWorld
Copy link

@orbeckst Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants