clean up XMFA parsing, allow spaces in parsing (ende++, from IRC)
[bioperl-live.git] / t / Structure.t
blob62d6e039cb6824a85d34a5e2e8c7990142ca668e
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN { 
7     use lib 't/lib';
8     use BioperlTest;
9     
10     test_begin(-tests => 51);
11         
12         use_ok('Bio::Structure::Entry');
13         use_ok('Bio::Structure::Model');
14         use_ok('Bio::Structure::Chain');
15         use_ok('Bio::Structure::Residue');
16         use_ok('Bio::Structure::Atom');
19 ok my $entry = Bio::Structure::Entry->new;
20 isa_ok $entry, 'Bio::Structure::Entry';
22 ok my $model = Bio::Structure::Model->new;
23 isa_ok $model, 'Bio::Structure::Model';
25 ok my $chain = Bio::Structure::Chain->new;
26 isa_ok $chain, 'Bio::Structure::Chain';
28 ok my $residue = Bio::Structure::Residue->new;
29 isa_ok $residue, 'Bio::Structure::Residue';
31 ok my $atom = Bio::Structure::Atom->new;
32 isa_ok $atom, 'Bio::Structure::Atom';
34 # adding/removing to Entry
35 my $m1 = Bio::Structure::Model->new;
36 $entry->model($m1);
37 is $entry->model,1;
38 my $m2 = Bio::Structure::Model->new;
39 $entry->add_model($m2);
40 is $entry->get_models, 2;
42 $entry->model($m2);
43 is $entry->model, 1;
44 my @m = ($m1, $m2);
45 $entry->model(\@m);
46 is $entry->model, 2;
48 # does $m2 gest orphaned
49 $entry->model($m1);
50 is $entry->parent($m2), undef;
53 # adding/removing to Model 
54 my $c1 = Bio::Structure::Chain->new;
55 $entry->add_chain($model,$c1);
56 is $entry->get_chains($model),1;
57 my $c2 = Bio::Structure::Chain->new;
58 $entry->add_chain($model,$c2);
59 is $entry->get_chains($model), 2;
60 isa_ok $entry->parent($c1), 'Bio::Structure::Model';
61 is $entry->parent($c1), $entry->parent($c2);
64 # adding/removing to Chain 
65 my $r1 = Bio::Structure::Residue->new;
66 $entry->add_residue($chain,$r1);
67 is $entry->get_residues($chain),1;
68 my $r2 = Bio::Structure::Residue->new;
69 $entry->add_residue($chain,$r2);
70 is $entry->get_residues($chain), 2;
72 isa_ok $entry->parent($r2), 'Bio::Structure::Chain';
73 is $entry->parent($r1), $entry->parent($r2);
75 # adding/removing to Residue 
76 $entry->add_atom($residue,$atom);
77 is $entry->get_atoms($residue),1;
78 my $a2 = Bio::Structure::Atom->new;
79 my $a3 = Bio::Structure::Atom->new;
80 my $a4 = Bio::Structure::Atom->new;
81 my $a5 = Bio::Structure::Atom->new;
82 my $a6 = Bio::Structure::Atom->new;
83 $entry->add_atom($residue,$a2);
84 is $entry->get_atoms($residue), 2;
86 my @a = ($a3, $a4, $a5);
87 $entry->add_atom($r2,\@a);
88 is $entry->get_atoms($r2), 3;
90 isa_ok $entry->parent($a2), 'Bio::Structure::Residue';
91 is $entry->parent($a3), $entry->parent($a5);
94 $atom->x(10.234);
95 is $atom->x, 10.234;
96 my $y = 12.345;
97 $atom->y($y);
98 is $atom->y, $y;
99 my $z = $atom->x - $y;
100 $atom->z($z);
101 is $atom->z, -2.111;
102 my @xyz = $atom->xyz;
103 is (scalar (@xyz), 3);
105 is $xyz[0], 10.234;
106 is $xyz[1], 12.345;
107 is $xyz[2], -2.111;
109 ok my $e2 = Bio::Structure::Entry->new(-id => "Entry 2");
110 is $e2->id, "Entry 2";
111 ok my $m3 = Bio::Structure::Model->new(-id => "Model 2");
112 is $m3->id, "Model 2";
113 ok my $c3 = Bio::Structure::Chain->new(-id => "Chain 2");
114 is $c3->id, "Chain 2";
115 ok my $r3 = Bio::Structure::Residue->new(-id => "Residue 2");
116 is $r3->id, "Residue 2";
117 ok $a2 = Bio::Structure::Atom->new(-id => "Atom 2");
118 is $a2->id, "Atom 2";
120 $entry->add_atom($r3,$a6);
121 $entry->add_residue($c3,$r3);
122 is $entry->parent( $entry->parent($a6) )->id , "Chain 2";