Chem-Structure-Parser

 view release on metacpan or  search on metacpan

t/header.t  view on Meta::CPAN

COMPND   6 CHAIN: A;
ATOM      1  CA  ALA A   1      10.000  10.000  10.000  1.00 20.00           C
PDB
	is($c->{chains}{A}{molecule}, 'FIRST THING', 'a chain two MOL_IDs claim is the first one\'s');
}

# The records a file old enough to keep its entry id in columns 73-80 has there
# instead of text.  Each field below is read to the end of the line, or into
# those columns, and came back with the id on the end until 0.039.  The lines
# are built on the layout of gemmi's tests/pdb1gdr.ent, which has none of
# these records itself.
{
	my $old = sub { sprintf "%-72s%-4s%4d\n", $_[0], '9OLD', $_[1] };
	my $c = structure_info_string(
		  sprintf("%-72s%-8s\n", 'HEADER    TEST                                    01-JAN-94   9OLD', '9OLD   1')
		. $old->('SEQADV 9OLD MSE A    7  UNP  P12345    MET     7 MODIFIED RESIDUE', 2)
		. $old->('MODRES 9OLD MSE A    7  MET  SELENOMETHIONINE', 3)
		. $old->('HETNAM      ZN ZINC ION', 4)
		. $old->('HETSYN      ZN ZINC', 5)
		. $old->('FORMUL   4   ZN    ZN 2+', 6)
		. $old->('SSBOND   1 CYS A    6    CYS A   11', 7)
		. $old->('LINK         ZN    ZN A 101                 SG  CYS A   6', 8)
		. $old->('REVDAT   1   31-JAN-94 9OLD    0', 9)
		. $old->('REMARK   2 RESOLUTION. 2.00 ANGSTROMS.', 10)
		. "ATOM      1  CA  ALA A   1      10.000  10.000  10.000  1.00 20.00           C\n");
	is($c->{seqadv}[0]{comment}, 'MODIFIED RESIDUE', 'SEQADV: the comment stops before the id');
	is($c->{modres}{MSE}{comment}, 'SELENOMETHIONINE', 'MODRES: and so does this one');
	is($c->{het}{ZN}{name}, 'ZINC ION', 'HETNAM: the name');
	is($c->{het}{ZN}{synonym}, 'ZINC', 'HETSYN: the synonym');
	is($c->{het}{ZN}{formula}, 'ZN 2+', 'FORMUL: the formula');
	is($c->{ssbond}[0]{length}, '', 'SSBOND: a length the id stands in for is no length');
	is($c->{link}[0]{length}, '', 'LINK: nor here');
	is($c->{revdat}[0]{what}, '', 'REVDAT: and the id is not a record the revision touched');
	is($c->{remarks}{2}[0], 'RESOLUTION. 2.00 ANGSTROMS.', 'REMARK: nor part of the text');
}

#--------
# SEQRES, DBREF, SEQADV, MODRES
#--------
is_deeply($i->{seqres}{A}{residues},
	[ qw(MET ALA GLY LEU LYS CYS MSE HIS HIS SER CYS) ],
	'SEQRES: the three-letter residues, in order');
is($i->{seqres}{A}{length}, 11, 'SEQRES: the declared length');
is($i->{seqres}{A}{sequence}, 'MAGLKCMHHSC', 'SEQRES: as single letters');
is($i->{dbref}{A}[0]{database},  'UNP',        'DBREF: database');
is($i->{dbref}{A}[0]{accession}, 'P12345',     'DBREF: accession');
is($i->{dbref}{A}[0]{db_id},     'TEST_HUMAN', 'DBREF: entry name');
is_deeply($i->{dbref}{B}, [ {
	chain => 'B', seq_begin => '1', seq_end => '4', database => 'GB',
	accession => 'AB0123456789', db_id => 'TEST_SEQUENCE_LONG',
	db_begin => '101', db_end => '104',
} ], 'DBREF1/DBREF2: a reference too long for DBREF is read off the pair');
is($i->{seqadv}[0]{resname}, 'MSE', 'SEQADV: the residue that differs');
is($i->{seqadv}[0]{database}, 'UNP', 'SEQADV: the database it differs from');
is($i->{seqadv}[0]{comment}, 'MODIFIED RESIDUE', 'SEQADV: why');
is($i->{modres}{MSE}{standard}, 'MET', 'MODRES: what the modified residue stands for');

#--------
# heterogens
#--------
is($i->{het}{NAG}{name}, '2-ACETAMIDO-2-DEOXY-BETA-D-GLUCOPYRANOSE', 'HETNAM');
is($i->{het}{NAG}{formula}, 'C8 H15 N O6', 'FORMUL');
is($i->{het}{NAG}{instances}[0]{chain}, 'A', 'HET: which chain the heterogen is in');
is($i->{het}{NAG}{instances}[0]{natoms}, '14', 'HET: how many atoms it should have');
is($i->{het}{ZN}{name}, 'ZINC ION', 'HETNAM for a two-letter het id');
is($i->{het}{HOH}{water}, 1, 'FORMUL: the asterisk marks the water');

#--------
# secondary structure and bonds
#--------
is($i->{helix}[0]{init_resname}, 'MET', 'HELIX: first residue');
is($i->{helix}[0]{end_resseq},   '3',   'HELIX: last residue');
is($i->{helix}[0]{init_chain},   'A',   'HELIX: chain');
is($i->{sheet}[0]{init_resname}, 'CYS', 'SHEET: first residue');
is($i->{sheet}[0]{n_strands},    '2',   'SHEET: strand count');
is($i->{sheet}[0]{sense},        '0',   'SHEET: the first strand has a sense of 0');
is($i->{sheet}[1]{sense},        '-1',  'SHEET: and an antiparallel one after it -1');
is_deeply($i->{ssbond}[0], { chain1 => 'A', resseq1 => '6', chain2 => 'A', resseq2 => '10', length => '2.03' },
	'SSBOND: both ends and the distance');
is($i->{link}[0]{name1}, 'ZN',  'LINK: first atom');
is($i->{link}[0]{chain1}, 'A',  'LINK: first chain, which is two columns right of the residue name');
is($i->{link}[0]{name2}, 'SG',  'LINK: second atom');
is($i->{link}[0]{resseq2}, '6', 'LINK: second residue');
is($i->{cispep}[0]{resname1}, 'GLY', 'CISPEP');
is($i->{cispep}[0]{angle}, '-0.42', 'CISPEP: the measured angle');

#--------
# crystal and connectivity
#--------
is($i->{cryst1}{a}, 40.1, 'CRYST1: a');
is($i->{cryst1}{b}, 50.2, 'CRYST1: b');
is($i->{cryst1}{c}, 60.3, 'CRYST1: c');
is($i->{cryst1}{alpha}, 90, 'CRYST1: alpha');
is($i->{cryst1}{beta}, 95.5, 'CRYST1: beta');
is($i->{cryst1}{sgroup}, 'P 1 21 1', 'CRYST1: space group');
is($i->{cryst1}{z}, '4', 'CRYST1: Z');
is_deeply($i->{conect}[0], [ '57', '58', '59' ], 'CONECT: the bonded serial numbers');

#--------
# a tally of every record in the file, so that a record the module does not
# parse can still be seen to be there
#--------
is($i->{records}{REMARK}, 9, 'records: how many of each record the file has');
is($i->{records}{SEQRES}, 2, 'records: SEQRES');
ok(exists $i->{records}{MASTER}, 'records: even the ones nothing is done with');

#--------
# meta => 0 skips all of it
#--------
{
	my $n = structure_info("$data/mini.pdb", meta => 0);
	is($n->{title}, undef, 'meta => 0: no header parsing');
	is($n->{chains}{A}{sequence}, 'MAGCMHHSC', 'but the coordinates are still read');
	is($n->{id}, 'MINI', 'and the id falls back to the file name');
}

#--------
# Header fields that are not what they are declared to be.  These are not
# hypothetical: every one is taken from an entry in PDBbind v2020, and each of
# them used to be fatal or wrong.
#--------



( run in 1.280 second using v1.01-cache-2.11-cpan-1bcd28dbaf1 )