dimchris / mdanalysis

Automatically exported from code.google.com/p/mdanalysis
0 stars 0 forks source link

How do I save a custom selection to pdb file? #118

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

I have a small pdb file, and I want to get a pdb file of shifted copies of that 
pdb file. So I have an array of vectors, and a small pdb file.

So I open pdf file many times, and each time I make a moved selection, and I 
append selection.

If I save traslated selections -- pdf files are translated, but when I save a 
selection, to which I have appended all that -- the resulting file is not:

The code:

universe = Universe(args.myStr)
universeMoved = universe.atoms.translate(MoveByVectors[0])
All = universe.selectAtoms("all")

for Number, Vector in enumerate(MoveByVectors[1:]):
    print Vector, Number
    universe = Universe(args.myStr)
    AllTemp = universe.selectAtoms("all")
    AllTemp.translate(Vector)
    AllTemp.write(myBody + "_" + str(Number) + myExt)
    All += AllTemp

So AllTemp files are translated, but my custom selection with all the 
structures (All) is not. What do I do wrong?

Is anything in what I say is unclear?

Original issue reported on code.google.com by kheyfbo...@gmail.com on 17 Oct 2012 at 5:35

GoogleCodeExporter commented 9 years ago
Hi kheyfboris,

A selection is still part of its Universe and any changes will change the 
underlying coordinates. You cannot simply duplicate a selection and make it 
independent of the Universe (i.e. in Python speak there's no "deep copy"). 
Think of selections as "pointers" to atoms. Whenever you change the selection 
you're changing the underlying Atom object.

I think your code should correctly write out shifted copies but your All atom 
group will simply contain len(MoveByVectors)-1 copies of the selection, and 
they will all have the coordinates shifted by np.sum(MoveByVectors,axis=1). 

I think this problem is better discussed on the user mailing list so I am 
closing it. If you think that this is bug or if you want to formulate a feature 
request then you're of course welcome reopen the Issue (just add a comment to 
this effect, describing the details).

If you're interested in using MDAnalysis for system building (e.g. create 
multiple copies of a solvent molecule and translate) then you check with Andy 
Somogyi who has been working on extending MDAnalysis substantially in this 
direction.

Oliver

Original comment by orbeckst on 17 Oct 2012 at 9:18

GoogleCodeExporter commented 9 years ago
Oh, Ok then. I managed to do what I needed any way: I wrote several pdbs to a 
newly created dir, renumbered them with editconf, and merged them with pymol:

for Number, Vector in enumerate(MoveByVectors):
    # loading:
    universe = Universe(args.myStr)
    Temp = universe.selectAtoms("all")
    # translation:
    Temp.translate(Vector)
    # rotation:
    RotationPoint = Temp.atoms.centerOfGeometry()
    perpVector = r_[Vector[1], -Vector[0], Vector[2]] # perpendicular to Vector in the x-y plane -- to rotate the thing about
    Rotation = rotation_matrix(-AngleRad, perpVector, RotationPoint)
    Temp.atoms.rotate(Rotation[:3,:3])
    # saving:
    fileName = myBody + "_" + "{0:03d}".format(Number + 1) + myExt
    Temp.write(fileName)
    # renumber:
    subprocess.check_call("editconf{wW} -f {File} -o {File} -resnr {Num}".format(File = fileName, wW = args.wW, Num = Number + 1), shell=True, cwd=os.getcwd())

Original comment by kheyfbo...@gmail.com on 18 Oct 2012 at 1:07

Attachments: