Skip to content

Commit a460241

Browse files
committed
Fix code style issues
1 parent 05e1f0f commit a460241

File tree

6 files changed

+62
-72
lines changed

6 files changed

+62
-72
lines changed

FlexLabel/python/LabelLib_pymol.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
# Usage example:
77
# fetch 1BNA, async=0
8-
# remove solvent
8+
# remove solvent
99
# genAV('1BNA', '/1BNA/B/B/19/C5', allowed_sphere_radius=1.5)
1010
## genAV('1BNA', '/1BNA/B/B/19/C5', linker_length=22.0, linker_diameter=3.0, dye_radius=4.0, disc_step=0.7, allowed_sphere_radius=2.0)
1111
def genAV(obstacles, attachment, linker_length=20.0, linker_diameter=2.0, dye_radius=3.5, disc_step=0.9, name=None, state=1, stripsc=True, allowed_sphere_radius=0.0, smoothSurf=True):
12-
12+
1313
source = np.array(cmd.get_model(attachment, state).get_coord_list())
1414
if (source.shape[0]!=1):
1515
print('attachment selection must contain exactly one atom, selected: {}'.format(source.shape[0]))
1616
return
1717
source=source.reshape(3)
18-
18+
1919
srcAt = cmd.get_model(attachment, state).atom[0]
2020
srcModelName = cmd.get_names('objects',0,attachment)[0]
21-
21+
2222
obstacles = '(' + obstacles + ') and not (' + attachment + ')'
2323
if stripsc and isAA(srcAt.resn):
2424
obstacles += ' and not (' + srcModelName
@@ -27,7 +27,7 @@ def genAV(obstacles, attachment, linker_length=20.0, linker_diameter=2.0, dye_ra
2727
obstacles+=' and resi '+srcAt.resi+' and sidechain'+')'
2828
if allowed_sphere_radius > 0.0:
2929
obstacles+=' and not (({}) around {})'.format(attachment, allowed_sphere_radius)
30-
30+
3131
xyzRT=np.zeros((1,4))
3232
nAtoms=cmd.count_atoms(obstacles)
3333
if nAtoms>0:
@@ -36,7 +36,7 @@ def genAV(obstacles, attachment, linker_length=20.0, linker_diameter=2.0, dye_ra
3636
xyzRT=np.zeros((nAtoms,4))
3737
for i,at in enumerate(atoms):
3838
xyzRT[i]=[at.coord[0],at.coord[1],at.coord[2],at.vdw]
39-
39+
4040
av1=ll.dyeDensityAV1(xyzRT.T,source,linker_length, linker_diameter, dye_radius, disc_step)
4141
m=avToModel(av1)
4242
if len(m.atom)==0:
@@ -48,7 +48,7 @@ def genAV(obstacles, attachment, linker_length=20.0, linker_diameter=2.0, dye_ra
4848
name += srcAt.chain + '-'
4949
name += srcAt.resi + '-' + srcAt.name
5050
cmd.load_model(m, name)
51-
51+
5252
if smoothSurf:
5353
surfName=name+'_surf'
5454
mapName=name+'_map'
@@ -68,7 +68,7 @@ def isAA(resn):
6868
return True
6969
return False
7070

71-
def makeAtom(index, xyz, vdw, name='AV'):
71+
def makeAtom(index, xyz, vdw, name='AV', q=1.0):
7272
atom = chempy.Atom()
7373
atom.index = index
7474
atom.name = name
@@ -81,7 +81,7 @@ def makeAtom(index, xyz, vdw, name='AV'):
8181
atom.vdw=vdw
8282
atom.hetatm = False
8383
atom.b = 100
84-
atom.q = 1
84+
atom.q = q
8585
return atom
8686

8787
def avToModel(av):
@@ -91,15 +91,14 @@ def avToModel(av):
9191

9292
for i, p in enumerate(points.T):
9393
x, y, z, w = p
94-
m.add_atom(makeAtom(i+1, [x, y, z], r))
94+
m.add_atom(makeAtom(i+1, [x, y, z], r, q=w))
9595

9696
MP = np.average(points[:3,:],axis=1,weights=points[3])
9797
if points.shape[1]>0:
9898
m.add_atom(makeAtom(points.shape[1]+1,list(MP),2.0,'AVmp'))
99-
99+
100100
m.update_index()
101101
return m
102102

103103

104104
cmd.extend("genAV", genAV)
105-

FlexLabel/python/mdtraj_example.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,49 @@
88
import warnings
99

1010
# Prints inter-dye distance distribution histograms for each frame of a trajectory.
11-
# Labels are: donor at residue 2, acceptor at residue 27
11+
# Labels are: donor at residue 2, acceptor at residue 27
1212
def main(args):
1313
traj = md.load_pdb('http://www.rcsb.org/pdb/files/2EQQ.pdb')
14-
14+
1515
#strip sidechains of residues 2 and 27
1616
idxs=traj.topology.select('name CB CA N C or not (resSeq 2 or resSeq 27)')
1717
traj=traj.atom_slice(idxs)
18-
18+
1919
bins=np.linspace(0.0,80.0,41)
2020
bin_centers=bins[:-1]+(bins[1]-bins[0])/2.0
21-
21+
2222
#get the index of donor and acceptor attachment atoms
2323
donorAttIdx=traj.topology.select('name CB and resSeq 2')[0]
2424
acceptorAttIdx=traj.topology.select('name CB and resSeq 27')[0]
25-
25+
2626
#print header
2727
print('Frame#\t'+'A\t'.join('{:.1f}'.format(e) for e in bin_centers))
28-
28+
2929
for frIdx in range(traj.n_frames):
3030
gridDonor=genAV(traj, frIdx, donorAttIdx, 20.0, 2.0, 3.5, 0.9, 0.3, 3.5+3.0)
3131
gridAcceptor=genAV(traj, frIdx, acceptorAttIdx, 22.0, 2.0, 3.5, 0.9, 0.4, 3.5+3.0)
32-
32+
3333
donorVolSize=np.count_nonzero(np.array(gridDonor.grid) > 1.0)
3434
accVolSize=np.count_nonzero(np.array(gridAcceptor.grid) > 1.0)
35-
if donorVolSize==0 or accVolSize==0:
35+
if donorVolSize==0 or accVolSize==0:
3636
continue
37-
37+
3838
distances=ll.sampleDistanceDistInv(gridDonor,gridAcceptor,1000000)
39-
freq, bin_edges = np.histogram(distances,bins=bins)
39+
freq, _ = np.histogram(distances,bins=bins)
4040
print('{}\t'.format(frIdx)+'\t'.join(str(e) for e in freq))
41-
41+
4242

4343
# Converts mdtraj frame to xyzR array for LabelLib
4444
def xyzr(traj, frameId):
4545
vdw=np.empty(traj.n_atoms)
4646
for i,atom in enumerate(traj.topology.atoms):
4747
vdw[i]=atom.element.radius
4848
# For better performance `vdw` should be cached
49-
49+
5050
return np.column_stack([traj.xyz[frameId],vdw]).astype(np.float32).T*10.0
5151

5252
#cvRadius does not include the dyeRadius, so one would typically set cvRadius=dyeR+const
5353
def genAV(traj, frameId, attachmentIdx, length, width, radius, resolution, cvFrac=None, cvRadius=0.0):
54-
5554
atoms=xyzr(traj,frameId)
5655
atoms[3,attachmentIdx]=0.0 #attachment atom should not be an obstacle
5756
source=atoms[:3,attachmentIdx]
@@ -63,7 +62,7 @@ def genAV(traj, frameId, attachmentIdx, length, width, radius, resolution, cvFra
6362
surfaceAtoms=np.vstack([atoms,labels])
6463
surfaceAtoms[3]+=cvRadius
6564
acv = ll.addWeights(av,surfaceAtoms)
66-
65+
6766
#reweight
6867
acvarr=np.array(acv.grid)
6968
volCV = np.count_nonzero(acvarr > 1.0)

FlexLabel/python/usage.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def savePqrFromAtoms(fileName, atoms):
1616
with open(fileName, "w") as out:
1717
for i,at in enumerate(atoms.T):
1818
out.write(sz.format(i, i, at[0], at[1], at[2], 1.0, at[3]))
19-
20-
19+
20+
2121
atoms=np.array([
2222
[0.0, -4.0, 22.0, 1.5],
2323
[9.0, 0.0, 0.0, 3.0],
@@ -37,17 +37,17 @@ def savePqrFromAtoms(fileName, atoms):
3737
dye_radius_1 = 3.5
3838
simulation_grid_spaceing = 0.9
3939
av1 = ll.dyeDensityAV1(
40-
atoms, source,
41-
linker_length,
42-
linker_width,
43-
dye_radius_1,
40+
atoms, source,
41+
linker_length,
42+
linker_width,
43+
dye_radius_1,
4444
simulation_grid_spaceing
4545
)
4646
minLengthGrid = ll.minLinkerLength(
47-
atoms, source,
48-
linker_length,
49-
linker_width,
50-
dye_radius_1,
47+
atoms, source,
48+
linker_length,
49+
linker_width,
50+
dye_radius_1,
5151
simulation_grid_spaceing
5252
)
5353

FlexLabel/src/FlexLabel.cxx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Grid3DExt final : public Grid3D
6161
std::numeric_limits<int>::max();
6262
}
6363

64-
Grid3DExt(const Grid3D &grid) : Grid3D(grid)
64+
explicit Grid3DExt(const Grid3D &grid) : Grid3D(grid)
6565
{
6666
originAdj = Vec4f(originXYZ).array() - 0.5f * discStep;
6767
originAdj[3] = 0.0f;
@@ -104,7 +104,7 @@ class Grid3DExt final : public Grid3D
104104
private:
105105
Eigen::Vector4f originAdj; // originXYZ - discStep*0.5
106106
Eigen::Array4i shape4i;
107-
float devNull;
107+
float devNull = 0.0f;
108108

109109
Eigen::Array4i getIjk(const Eigen::Vector4f &xyz);
110110

@@ -154,9 +154,8 @@ std::vector<Grid3DExt::edge_t> Grid3DExt::essentialNeighbours()
154154
allowedDist << 1.0f, 2.0f, 3.0f, 5.0f, 6.0f;
155155
allowedDist = allowedDist.cwiseSqrt() * discStep;
156156
std::vector<edge_t> edges;
157-
float minDiff;
158157
for (const edge_t &e : fullList) {
159-
minDiff = (allowedDist.array() - e.r).cwiseAbs().minCoeff();
158+
float minDiff = (allowedDist.array() - e.r).cwiseAbs().minCoeff();
160159
if (minDiff < discStep * 0.01f) {
161160
edges.push_back(e);
162161
}
@@ -257,10 +256,9 @@ void Grid3DExt::excludeConcentricSpheres(const Eigen::Matrix4Xf &xyzR,
257256
const float l2out = std::pow(maxL + maxRclash, 2.0f);
258257

259258
Vector4f at;
260-
float rAt;
261259
for (int iAtom = 0; iAtom < xyzR.cols(); ++iAtom) {
262260
at = xyzR.col(iAtom);
263-
rAt = at[3];
261+
float rAt = at[3];
264262
at[3] = 0.0f;
265263
const float dist2 = (center - at).squaredNorm();
266264
if (dist2 > l2out) {
@@ -594,7 +592,7 @@ double meanDistanceInv(const Grid3D &g1, const Grid3D &g2,
594592
}
595593

596594
std::vector<float> sampleDistanceDistInv(const Grid3D &g1, const Grid3D &g2,
597-
const unsigned nsamples)
595+
const unsigned nsamples)
598596
{
599597
// Draw distances using Inverse transform sampling
600598

@@ -636,13 +634,12 @@ double meanEfficiencyUniform(const Grid3D &g1, const Grid3D &g2, const float R0,
636634
const unsigned size2 = p2.cols();
637635

638636
double totalW = 0.0;
639-
double e = 0., w;
640-
unsigned i, j;
637+
double e = 0.;
641638
Eigen::Vector4f tmp;
642639
for (unsigned s = 0; s < nsamples; s++) {
643-
i = rng(size1);
644-
j = rng(size2);
645-
w = p1(3, i) * p2(3, j);
640+
unsigned i = rng(size1);
641+
unsigned j = rng(size2);
642+
double w = p1(3, i) * p2(3, j);
646643
totalW += w;
647644
tmp = p1.col(i) - p2.col(j);
648645
tmp[3] = 0.0f;
@@ -664,13 +661,12 @@ double meanDistanceUniform(const Grid3D &g1, const Grid3D &g2,
664661
const unsigned size2 = p2.cols();
665662

666663
double totalW = 0.0;
667-
double r = 0., w;
668-
unsigned i, j;
664+
double r = 0.;
669665
Eigen::Vector4f tmp;
670666
for (unsigned s = 0; s < nsamples; s++) {
671-
i = rng(size1);
672-
j = rng(size2);
673-
w = p1(3, i) * p2(3, j);
667+
unsigned i = rng(size1);
668+
unsigned j = rng(size2);
669+
double w = p1(3, i) * p2(3, j);
674670
totalW += w;
675671
tmp = p1.col(i) - p2.col(j);
676672
tmp[3] = 0.0f;

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![Anaconda-Server Version](https://anaconda.org/tpeulen/labellib/badges/version.svg)](https://anaconda.org/tpeulen/labellib)
66
[![Anaconda-Server Downloads](https://anaconda.org/tpeulen/labellib/badges/downloads.svg)](https://anaconda.org/tpeulen/labellib)
77

8-
98
## General description
109
LabelLib is a low-level C++ library for the simulation of small probes flexibly coupled to biomolecules for the
1110
development of higher-level applications and libraries. LabelLib can calculate the distribution of flexible labels
@@ -20,7 +19,6 @@ probe are approximated by a tube and soft sphere, respectively. Details are prov
2019
[![DOI for citing FPS](https://img.shields.io/badge/DOI-10.1038%2Fnmeth.2222-blue.svg)](https://doi.org/10.1038/nmeth.2222)
2120
[![DOI for citing FPS](https://img.shields.io/badge/DOI-10.1021%2Fja105725e-blue.svg)](https://doi.org/10.1021/ja105725e).
2221

23-
2422
![dsDNA and an AV surface][2]
2523

2624
LabelLib is a library for programmers and provides APIs for C/C++ and Python. Furthermore, LabelLib can be integrated
@@ -46,10 +44,9 @@ MD-simulations and the development of Python scripts handling FRET-based structu
4644
structural modeling. FPS can calculate accessible volumes (AVs), screen a set of structural models against experimental
4745
observables, and can generate new structural models by rigid-body docking using experimental FRET data.
4846

47+
## Building and installation
4948

50-
# Building and installation
51-
52-
## C++ shared library
49+
### C++ shared library
5350

5451
C++ shared library can be installed from source with cmake:
5552
```bash
@@ -66,7 +63,7 @@ cmake .. && make package
6663
sudo dpkg -i FlexLabel-*-Linux.deb
6764
```
6865

69-
## Python bindings
66+
### Python bindings
7067

7168
Python bindings can be be either installed via pip or conda. Installation of the C++ library is not necessary for this.
7269
The python binding can be installed via pip using the following command:
@@ -78,12 +75,11 @@ The python bindings can be installed via conda using the following command:
7875
conda install -c tpeulen labellib
7976
```
8077

78+
## Usage
8179

82-
# Usage
83-
84-
## Pymol
80+
### Pymol
8581

86-
To access the functionality of LabelLib in PyMOL two basic prerequisites need to be fulfilled:
82+
To access the functionality of LabelLib in [PyMOL][1] two basic prerequisites need to be fulfilled:
8783
1) LabelLib needs to be installed in the Python installation used by PyMOL
8884
2) The file [LabelLib_pymol.py](FlexLabel/python/LabelLib_pymol.py) needs to be downloaded and executed from
8985
PyMOL's command line interace.
@@ -116,7 +112,7 @@ As a result you should see something like this:
116112

117113
More extended examples of `genAV()` usage can be found in [LabelLib_pymol.py](FlexLabel/python/LabelLib_pymol.py).
118114

119-
## C++
115+
### C++
120116

121117
C++ usage example can be found in [testFlexLabel.cxx](FlexLabel/test/testFlexLabel.cxx). Your own software could be
122118
compiled like this:
@@ -128,7 +124,7 @@ g++ -std=c++14 -O3 -o FlexLabelTest testFlexLabel.cxx -lFlexLabel
128124
Possible output:
129125
> AV calculation took: 20.783 ms
130126
131-
## Python
127+
### Python
132128

133129
The LabelLib can be used from python as shown below in a code example.
134130
LabelLib requires the Cartesian-coordinates, xyz, and van der Waals radii, vdW, of the biomolecule the label is
@@ -163,7 +159,7 @@ grid3d = np.array(grid).reshape(shape, order='F')
163159
```
164160
Another usage example is available in [usage.py](FlexLabel/python/usage.py)
165161

166-
# Citation
162+
## Citation
167163
If you have used LabelLib in a scientific publication, we would appreciate citations to the following paper:
168164
[![DOI for citing LabelLib](https://img.shields.io/badge/DOI-10.1016%2Fj.sbi.2016.11.012-blue.svg)](https://doi.org/10.1016/j.sbi.2016.11.012)
169165
> Dimura, M., Peulen, T.O., Hanke, C.A., Prakash, A., Gohlke, H. and Seidel, C.A., 2016. Quantitative FRET studies and integrative modeling unravel the structure and dynamics of biomolecular systems. Current opinion in structural biology, 40, pp.163-185.

0 commit comments

Comments
 (0)