LOOS  v2.3.2
center_molecule.py
1 #!/usr/bin/env python
2 """
3  Center an entire model based on a selection.
4 """
5 """
6 
7  This file is part of LOOS.
8 
9  LOOS (Lightweight Object-Oriented Structure library)
10  Copyright (c) 2012 Tod Romo, Grossfield Lab
11  Department of Biochemistry and Biophysics
12  School of Medicine & Dentistry, University of Rochester
13 
14  This package (LOOS) is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation under version 3 of the License.
17 
18  This package is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program. If not, see <http://www.gnu.org/licenses/>.
25 """
26 
27 
28 
29 # Import LOOS
30 from loos import *
31 import sys
32 
33 ## Command line arguments
34 model_name = sys.argv[1]
35 selection = sys.argv[2]
36 
37 # Create the model
38 model = createSystem(model_name)
39 
40 # Select the requested atoms
41 subset = selectAtoms(model, selection)
42 
43 # Compute centroid the old-fashioned way...
44 center = GCoord(0,0,0)
45 for atom in subset:
46  center = center + atom.coords()
47 center = center / len(subset)
48 
49 for atom in subset:
50  atom.coords(atom.coords() - center)
51 
52 # Convert to a PDB
53 pdb = PDB.fromAtomicGroup(model)
54 
55 # Add a REMARK to the PDB
56 pdb.remarks().add("Structure centered using '" + selection + "'")
57 
58 # Print it to stdout...
59 print pdb
AtomicGroup createSystem(const std::string &filename)
Factory function for reading in structure files.
Definition: sfactories.cpp:115
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195