rubabel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ Visit=
2
+ Visit
3
+ set_idx
4
+ set_id
5
+ set_bo
6
+ set_bond_order
7
+ set_begin
8
+ set_end
9
+ set_parent
10
+ set_length
11
+ set
12
+ set_ksingle
13
+ set_kdouble
14
+ set_ktriple
15
+ set_aromatic
16
+ set_wedge
17
+ set_hash
18
+ set_wedge_or_hash
19
+ set_up
20
+ set_down
21
+ set_in_ring
22
+ set_closure
23
+ unset_hash
24
+ unset_wedge
25
+ unset_up
26
+ unset_down
27
+ unset_aromatic
28
+ unset_kekule
29
+ get_idx
30
+ get_id
31
+ get_bo
32
+ get_bond_order
33
+ get_flags
34
+ get_begin_atom_idx
35
+ get_end_atom_idx
36
+ get_begin_atom
37
+ get_end_atom
38
+ get_nbr_atom
39
+ get_parent
40
+ get_equib_length
41
+ get_length
42
+ get_nbr_atom_idx
43
+ find_smallest_ring
44
+ is_aromatic
45
+ is_in_ring
46
+ is_rotor
47
+ is_amide
48
+ is_primary_amide
49
+ is_secondary_amide
50
+ is_tertiary_amide
51
+ is_ester
52
+ is_carbonyl
53
+ is_single
54
+ is_double
55
+ is_triple
56
+ is_ksingle
57
+ is_kdouble
58
+ is_ktriple
59
+ is_closure
60
+ is_up
61
+ is_down
62
+ is_wedge
63
+ is_hash
64
+ is_wedge_or_hash
65
+ is_cis_or_trans
66
+ is_double_bond_geometry
67
+ clear
68
+ do_transformations
69
+ get_title
70
+ set_title
71
+ has_data
72
+ delete_data
73
+ clone_data
74
+ data_size
75
+ get_all_data
76
+ get_data
77
+ begin_data
78
+ end_data
79
+
@@ -0,0 +1,52 @@
1
+ module ObjectSpace
2
+ class << self
3
+ include Enumerable
4
+ alias_method :each, :each_object
5
+ end
6
+ def self.modules
7
+ self.select {|obj| obj.is_a?(Module) }
8
+ end
9
+ end
10
+
11
+ class Dog
12
+ end
13
+
14
+ before = ObjectSpace.modules
15
+
16
+ require 'openbabel'
17
+
18
+ after = ObjectSpace.modules
19
+
20
+ modules = (after - before).reject {|mod| mod.to_s =~ /SWIG/i }
21
+
22
+ class Object
23
+ def arity_hash
24
+ uniq = self.methods - (Object.new.methods + Object.methods)
25
+ Hash[ uniq.map do |name|
26
+ [name.to_s, self.method(name).arity]
27
+ end
28
+ ]
29
+ end
30
+ end
31
+
32
+ modules.each do |mod|
33
+ obj_hash =
34
+ if mod.respond_to?(:allocate)
35
+ begin
36
+ obj = mod.allocate
37
+ obj.arity_hash
38
+ rescue
39
+ {}
40
+ end
41
+ else
42
+ {}
43
+ end
44
+ klss_hash = mod.arity_hash
45
+ if (obj_hash.size + klss_hash.size) > 0
46
+ puts "*" * 50
47
+ puts mod
48
+ puts "*" * 50
49
+ puts obj_hash.map {|pair| pair.join(" ") }
50
+ puts klss_hash.map {|pair| pair.join(" ") }
51
+ end
52
+ end
@@ -0,0 +1,183 @@
1
+ #<OpenBabel::OBMol:0x00000000b71c90>
2
+ ---
3
+ - add
4
+ - reserve_atoms
5
+ - create_atom
6
+ - create_bond
7
+ - create_residue
8
+ - destroy_atom
9
+ - destroy_bond
10
+ - destroy_residue
11
+ - add_atom
12
+ - insert_atom
13
+ - add_bond
14
+ - add_residue
15
+ - new_atom
16
+ - new_bond
17
+ - new_residue
18
+ - delete_atom
19
+ - delete_bond
20
+ - delete_residue
21
+ - begin_modify
22
+ - end_modify
23
+ - get_mod
24
+ - increment_mod
25
+ - decrement_mod
26
+ - get_flags
27
+ - get_title
28
+ - num_atoms
29
+ - num_bonds
30
+ - num_hvy_atoms
31
+ - num_residues
32
+ - num_rotors
33
+ - get_atom
34
+ - get_atom_by_id
35
+ - get_first_atom
36
+ - get_bond_by_id
37
+ - get_bond
38
+ - get_residue
39
+ - get_internal_coord
40
+ - get_torsion
41
+ - get_angle
42
+ - get_formula
43
+ - get_spaced_formula
44
+ - get_mol_wt
45
+ - get_exact_mass
46
+ - get_total_charge
47
+ - get_total_spin_multiplicity
48
+ - get_dimension
49
+ - get_coordinates
50
+ - get_sssr
51
+ - get_lssr
52
+ - automatic_formal_charge
53
+ - automatic_partial_charge
54
+ - set_title
55
+ - set_formula
56
+ - set_energy
57
+ - set_dimension
58
+ - set_total_charge
59
+ - set_total_spin_multiplicity
60
+ - set_internal_coord
61
+ - set_automatic_formal_charge
62
+ - set_automatic_partial_charge
63
+ - set_aromatic_perceived
64
+ - set_sssrperceived
65
+ - set_lssrperceived
66
+ - set_ring_atoms_and_bonds_perceived
67
+ - set_atom_types_perceived
68
+ - set_ring_types_perceived
69
+ - set_chains_perceived
70
+ - set_chirality_perceived
71
+ - set_partial_charges_perceived
72
+ - set_hybridization_perceived
73
+ - set_implicit_valence_perceived
74
+ - set_kekule_perceived
75
+ - set_closure_bonds_perceived
76
+ - set_hydrogens_added
77
+ - set_corrected_for_ph
78
+ - set_aromatic_corrected
79
+ - set_spin_multiplicity_assigned
80
+ - set_flags
81
+ - unset_aromatic_perceived
82
+ - unset_sssrperceived
83
+ - unset_ring_types_perceived
84
+ - unset_partial_charges_perceived
85
+ - unset_implicit_valence_perceived
86
+ - unset_hydrogens_added
87
+ - unset_flag
88
+ - renumber_atoms
89
+ - set_coordinates
90
+ - to_inertial_frame
91
+ - translate
92
+ - rotate
93
+ - kekulize
94
+ - perceive_kekule_bonds
95
+ - new_perceive_kekule_bonds
96
+ - delete_hydrogens
97
+ - delete_non_polar_hydrogens
98
+ - delete_hydrogen
99
+ - add_hydrogens
100
+ - add_polar_hydrogens
101
+ - strip_salts
102
+ - separate
103
+ - get_next_fragment
104
+ - convert_dative_bonds
105
+ - correct_for_ph
106
+ - assign_spin_multiplicity
107
+ - set_is_pattern_structure
108
+ - center
109
+ - set_torsion
110
+ - find_sssr
111
+ - find_lssr
112
+ - find_ring_atoms_and_bonds
113
+ - find_chiral_centers
114
+ - find_children
115
+ - find_largest_fragment
116
+ - contig_frag_list
117
+ - align
118
+ - connect_the_dots
119
+ - perceive_bond_orders
120
+ - find_angles
121
+ - find_torsions
122
+ - get_gtdvector
123
+ - get_givector
124
+ - get_gidvector
125
+ - has_2d
126
+ - has_3d
127
+ - has_non_zero_coords
128
+ - has_aromatic_perceived
129
+ - has_sssrperceived
130
+ - has_lssrperceived
131
+ - has_ring_atoms_and_bonds_perceived
132
+ - has_atom_types_perceived
133
+ - has_ring_types_perceived
134
+ - has_chirality_perceived
135
+ - has_partial_charges_perceived
136
+ - has_hybridization_perceived
137
+ - has_implicit_valence_perceived
138
+ - has_kekule_perceived
139
+ - has_closure_bonds_perceived
140
+ - has_chains_perceived
141
+ - has_hydrogens_added
142
+ - has_aromatic_corrected
143
+ - is_corrected_for_ph
144
+ - has_spin_multiplicity_assigned
145
+ - is_chiral
146
+ - empty
147
+ - num_conformers
148
+ - set_conformers
149
+ - add_conformer
150
+ - set_conformer
151
+ - copy_conformer
152
+ - delete_conformer
153
+ - get_conformer
154
+ - set_energies
155
+ - get_energies
156
+ - get_energy
157
+ - begin_conformer
158
+ - next_conformer
159
+ - get_conformers
160
+ - begin_atoms
161
+ - end_atoms
162
+ - begin_bonds
163
+ - end_bonds
164
+ - begin_residues
165
+ - end_residues
166
+ - begin_atom
167
+ - next_atom
168
+ - begin_bond
169
+ - next_bond
170
+ - begin_residue
171
+ - next_residue
172
+ - begin_internal_coord
173
+ - next_internal_coord
174
+ - clear
175
+ - do_transformations
176
+ - has_data
177
+ - delete_data
178
+ - clone_data
179
+ - data_size
180
+ - get_all_data
181
+ - get_data
182
+ - begin_data
183
+ - end_data
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rubabel/molecule'
4
+ require 'rubabel/atom'
5
+
6
+ describe Rubabel::Atom do
7
+ describe 'working with a complex molecule' do
8
+
9
+ before do
10
+ @mol = Rubabel::Molecule.from_file( TESTFILES + '/cholesterol.sdf' )
11
+ @atom = @mol.atoms.first
12
+ @mol_h = Rubabel::Molecule.from_file( TESTFILES + '/cholesterol.sdf' )
13
+ @mol_h.add_h!
14
+ @atom_with_h = @mol_h.atoms.first
15
+ end
16
+
17
+ attributes = {
18
+ charge: 0,
19
+ id: 0,
20
+ spin: 0,
21
+ }.each do |methd, exp|
22
+ it "has #{methd}" do
23
+ @atom.send(methd).should == exp
24
+ end
25
+ end
26
+
27
+ it 'can get the bonds' do
28
+ @atom.each_bond do |bond|
29
+ bond.should be_a(Rubabel::Bond)
30
+ end
31
+ @atom.bonds.size.should == 4
32
+ end
33
+
34
+ it 'can get the neighboring atoms' do
35
+ @atom.id.should == 0
36
+ @atom.atomic_num.should == 6
37
+ @atom.type.should == 'C3'
38
+ @atom.each_atom do |nbr_atom|
39
+ nbr_atom.should be_a(Rubabel::Atom)
40
+ nbr_atom.ob.equal?(@atom.ob).should be_false
41
+ end
42
+ @atom.atoms.size.should == 4
43
+ end
44
+
45
+ it '#coords gets the coordinates' do
46
+ @atom.coords
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rubabel/molecule'
4
+ require 'rubabel/bond'
5
+
6
+ describe Rubabel::Bond do
7
+ subject { Rubabel::Molecule.from_file( TESTFILES + '/cholesterol.sdf' ).bonds.first }
8
+
9
+ it 'is a Rubabel::Bond' do
10
+ subject.should be_a(Rubabel::Bond)
11
+ end
12
+
13
+ it 'knows what atoms it includes' do
14
+ subject.each_atom do |atom|
15
+ atom.should be_a(Rubabel::Atom)
16
+ end
17
+ subject.atoms.size.should == 2
18
+ end
19
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rubabel/molecule'
4
+
5
+ describe Rubabel::Molecule do
6
+ before(:each) do
7
+ @mol = Rubabel::Molecule.from_file( TESTFILES + '/cholesterol.sdf' )
8
+ end
9
+
10
+ attributes = {
11
+ charge: 0,
12
+ formula: "C27H46O",
13
+ dim: 2,
14
+ spin: 1,
15
+ }.each do |methd, exp|
16
+ it "has #{methd}" do
17
+ @mol.send(methd).should == exp
18
+ end
19
+ end
20
+
21
+ it '#each iterates through each atom in id order' do
22
+ cnt = 0
23
+ @mol.each do |atom|
24
+ atom.id.should == cnt
25
+ cnt += 1
26
+ end
27
+ @mol.atoms.size.should == 33
28
+ @mol.add_h!
29
+ @mol.atoms.size.should == 74
30
+ end
31
+
32
+ it 'calculates #ob_sssr (smallest set of smallest rings)' do
33
+ ar = @mol.ob_sssr
34
+ ar.should be_an(Array)
35
+ # in the future should be Rubabel::Ring
36
+ ar.first.should be_a(OpenBabel::OBRing)
37
+ end
38
+
39
+ describe 'breaking a molecule' do
40
+ before(:each) do
41
+ @mol = Rubabel::Molecule.from_string("NC(=O)CO")
42
+ end
43
+
44
+ it 'num_atoms, atoms and each_atom are sensitive to #add_h!' do
45
+ @mol.num_atoms.should == 5
46
+ @mol.atoms.size.should == 5
47
+ @mol.each_atom.map.to_a.size.should == 5
48
+ @mol.add_h!
49
+ @mol.num_atoms.should == 10
50
+ @mol.atoms.size.should == 10
51
+ @mol.each_atom.map.to_a.size.should == 10
52
+ end
53
+
54
+ it 'num_bonds, bonds and each_bond are also sensitive to #add_h!' do
55
+ @mol.num_bonds.should == 4
56
+ @mol.bonds.size.should == 4
57
+ @mol.each_bond.map.to_a.size.should == 4
58
+ @mol.add_h!
59
+ @mol.num_bonds.should == 9
60
+ @mol.bonds.size.should == 9
61
+ @mol.each_bond.map.to_a.size.should == 9
62
+ end
63
+
64
+ it 'can be split into multiple molecules' do
65
+ reply = @mol.split(@mol.bonds.first, @mol.bonds.last)
66
+ reply.should be_a(Array)
67
+ reply.size.should == 3
68
+ csmiles = reply.map(&:csmiles)
69
+ csmiles.sort.should == %w(N CC=O O).sort
70
+ end
71
+ end
72
+
73
+ describe 'matching patterns (SMARTS)' do
74
+ before(:each) do
75
+ @mol = Rubabel::Molecule.from_string("NC(=O)O")
76
+ end
77
+
78
+ it 'can match smarts patterns' do
79
+ smarts_pattern = 'C=O'
80
+ ar = @mol.matches(smarts_pattern)
81
+ ar.should be_a(Array)
82
+ ar.size.should == 1
83
+ ar.first.map(&:type).should == %w(Cac O.co2)
84
+
85
+ # reverse order of smiles gives reverse order
86
+ ar = @mol.matches(smarts_pattern.reverse)
87
+ ar.first.map(&:type).should == %w(Cac O.co2).reverse
88
+ end
89
+
90
+ end
91
+ end