Skip to content

Instantly share code, notes, and snippets.

@fglock
Created December 8, 2017 08:59
Show Gist options
  • Save fglock/7aea4fc6b47050bb6c097537dac85720 to your computer and use it in GitHub Desktop.
Save fglock/7aea4fc6b47050bb6c097537dac85720 to your computer and use it in GitHub Desktop.
mktop + strict
use strict;
my ($i, $j, $h);
my $A;
my $B;
my $C5;
my $D;
my $GROUP;
my $H;
my $N1;
my $N3;
my $P;
my $Z;
my $acid;
my $amide;
my $assign;
my $atom2;
my $atom;
my $c;
my $diol;
my $go_j;
my $gone;
my $group;
my $hemi;
my $k;
my $kill;
my $linha;
my $ok;
my $ring_bond;
my $str;
my $sulfonamide;
my $sum;
my $triol;
my $txt;
my $valenceg;
my @ATM;
my @BO;
my @BO_ene;
my @DIOL;
my @TRIOL;
my @Z;
my @array2;
my @array;
my @array_atom;
my @array_r;
my @atm;
my @bond;
my @bond_list;
my @dat;
my @defgroup;
my @dist;
my @ene;
my @group;
my @list;
my @makeg;
my @phosp;
my @purine;
my @ring;
my @symbol;
my @txt;
my @type;
my @valence;
$txt='1 C 2 3 4 5
2 H 1
3 H 1
4 H 1
5 N 6 7 1
6 O 5
7 O 5';
(@atm)=split(/ +/, '1 H 6 C 7 N 8 O 9 F 14 SI 15 P 16 S 17 CL 26 FE 36 BR 53 I');
for($i=0; $i<=$#atm-1; $i+=2) {$ATM[$atm[$i]]=$atm[$i+1];}
(@txt)=split('\n', $txt);
foreach $str (@txt) {
(@dat)=split(/ +/, $str);
$i=@dat[0];
$symbol[$i]=uc(@dat[1]);
for ($j=1; $j<=100; $j++) {
if ($symbol[$i] eq $ATM[$j]) {$Z[$i]=$j;last;}
}
$valence[$i]=$#dat-1;
$bond_list[$i] = "$dat[2]";
for($j=3; $j<=$#dat; $j++) {
$bond_list[$i] = "$bond_list[$i]:$dat[$j]";
}
}
$linha=$#txt+1;
for ($i=1; $i<=$linha; $i++) {
(@dat)=split(/:/, $bond_list[$i]);
$bond[$i][$Z[$dat[0]]]++;
for($j=1; $j<=$#dat; $j++) {
$bond[$i][$Z[$dat[$j]]]++;
}
}
$GROUP=1;
for ($i = 1; $i <= $linha; $i++) {
$Z = $Z[$i];
@array = split(/:/, $bond_list[$i]);
if ($Z[$i] == 6) {
$group[$i]=$GROUP;
$GROUP++;
}
if ($Z == 1) {
if ($bond[$i][6] == 1) {$type[$i]="opls_140";}
}
if ($Z == 6) {
if (&bondif($i,7,1,8,1,6,1) and $valence[$i] == 3) {$type[$i] = "opls_235";}
if (&bondif($i,7,1,8,1,1,1) and $valence[$i] == 3) {$type[$i] = "opls_235";}
if (&bondif($i,7,2,8,1) and $valence[$i] == 3) {$type[$i] = "opls_247";}
if (&bondif($i,8,2) and $valence[$i] == 4) {
$diol=0;
foreach $atom (@array) {
if ($Z[$atom] == 8) {
@array2 = split(/:/, $bond_list[$atom]);
foreach $atom2 (@array2) {
if ($Z[$atom2] == 1) {
$DIOL[$diol] = $atom;
$diol++;
}
}
}
}
if ($diol == 2) {
$type[$DIOL[0]] = "opls_169";
$type[$DIOL[1]] = "opls_169";
}
}
if (&bondif($i,8,3) and $valence[$i] == 4) {
$triol=0;
foreach $atom (@array) {
if ($Z[$atom] == 8) {
@array2 = split(/:/, $bond_list[$atom]);
foreach $atom2 (@array2) {
if ($Z[$atom2] == 1) {
$TRIOL[$triol] = $atom;
$triol++;
}
}
}
}
if ($triol == 3) {
$type[$TRIOL[0]] = "opls_171";
$type[$TRIOL[1]] = "opls_171";
$type[$TRIOL[2]] = "opls_171";
}
}
if (&bondif($i,6,1,1,3)) {$type[$i] = "opls_135";}
if (&bondif($i,6,2,1,2)) {$type[$i] = "opls_136";}
if (&bondif($i,6,3,1,1)) {$type[$i] = "opls_137";}
if (&bondif($i,6,4)) {$type[$i] = "opls_139";}
if (&bondif($i,9,3)) {$type[$i] = "opls_961";}
if (&bondif($i,9,2)) {$type[$i] = "opls_962";}
if ($valence[$i] == 2) {
if (&bondif($i,6,2)) {
$gone=0;
foreach $atom (@array) {
if ($gone == 0) {
if (&bondif($atom,1,3) or &bondif($atom,1,2)) {$type[$i] = "opls_927";}
elsif (&bondif($atom,1,1)) {$type[$i] = "opls_928";}
else {$type[$i] = "opls_929";}
}
if (&bondif($atom,6,2) and $valence[$atom] == 2) {
$gone = 1;
$type[$i] = "opls_931";
$type[$atom] = "opls_931";
}
if (&bondif($atom,1,1) and $valence[$atom] == 2) {$type[$atom] = "opls_925";}
}
}
}
if (&bondif($i,7,1,6,1) and $valence[$i] == 2) {$type[$i] = "opls_754";}
}
if ($Z == 7) {
if ($valence[$i] == 4) {
if (&bondif($i,1,0,6,4)) {$type[$i] = "opls_288";}
if (&bondif($i,1,1,6,3)) {$type[$i] = "opls_940";}
if (&bondif($i,1,3,6,1) or &bondif($i,1,2,6,2)) {$type[$i] = "opls_287";}
}
else {
$amide=0;
$sulfonamide=0;
@array = split(/:/, $bond_list[$i]);
foreach $atom (@array) {
if ($Z[$atom] == 6 and $valence[$atom] == 3) {
@array2 = split (/:/, $bond_list[$atom]);
foreach $atom2 (@array2) {
if ($Z[$atom2] == 8) {
$amide=1;
}
}
}
if ($Z[$atom] == 16 and &bondif($atom,8,2)) {
$sulfonamide=1;
}
}
if (&bondif($i,1,1)) {
$type[$i] = "opls_901";
if ($amide == 1) {
$type[$i] = "opls_238";
}
if ($sulfonamide == 1) {$type[$i] = "opls_480";}
}
if (&bondif($i,1,2)) {
if ($amide == 1) {
$type[$i] = "opls_237";
}
elsif ($sulfonamide == 1) {
$type[$i] = "opls_478";
}
else {
$type[$i] = "opls_900";
}
}
if (&bondif($i,1,0)) {
if ($amide == 1) {
if (&ring(0,5,$i,4)) {
$type[$i] = "opls_238";
if (&bondif($array_r[1],1,1)) {
$type[$array_r[1]] = "opls_246";
$type[$array_r[4]] = "opls_245";
}
if (&bondif($array_r[1],1,2)) {
$type[$array_r[1]] = "opls_245";
$type[$array_r[4]] = "opls_246";
}
}
else {
$type[$i] = "opls_239";
}
}
elsif ($sulfonamide == 1) {
$type[$i] = "opls_480";
}
else {
$type[$i] = "opls_902";
}
}
if (&bondif($i,8,2)) {
$type[$i] = "opls_760";
}
if (&bondif($i,6,1) and $valence[$i] == 1) {
$type[$i] = "opls_753";
}
}
}
if ($Z == 8) {
@array = split(/:/, $bond_list[$i]);
if ($bond[$i][6] == 1 and $valence[$i] == 1) {
foreach $atom (@array) {
if ($Z[$atom] == 6) {
@array2 = split (/:/, $bond_list[$atom]);
foreach $atom2 (@array2) {
if ($Z[$atom2] == 7) {
$type[$i]="opls_236";
}
if ($Z[$atom2] == 1 and $type[$i] !~ /opls/) {
$type[$i] = "opls_278";
}
}
if ($type[$i] !~ /opls/) {
$type[$i] = "opls_281";
}
}
}
}
if ($bond[$i][1] == 1 and $valence[$i] == 2) {
$type[$i] = "opls_154";
foreach $atom (@array) {
if ($Z[$atom] == 6) {
if (&bondif($atom,1,3)) {
$type[$atom] = "opls_157";
}
if (&bondif($atom,1,2)) {
$type[$atom] = "opls_157";
}
if (&bondif($atom,1,1)) {
$type[$atom] = "opls_158";
}
if (&bondif($atom,1,0)) {
$type[$atom] = "opls_159";
}
}
}
}
if (&bondif($i,6,2) and $valence[$i] == 2) {
$type[$i] = "opls_180";
foreach $atom (@array) {
if (&bondif($atom,1,3)) {
$type[$atom] = "opls_181";
}
if (&bondif($atom,1,2)) {
$type[$atom] = "opls_182";
}
if (&bondif($atom,1,1)) {
$type[$atom] = "opls_183";
}
if (&bondif($atom,1,0)) {
$type[$atom] = "opls_182";
}
}
}
}
if ($Z == 15) {
if (&bondif($i,6,4)) {
$type[$i] = "opls_781";
}
}
if ($Z == 16) {
if ($valence[$i] == 2) {
if (&bondif($i,6,1,1,1)) {
$type[$i] = "opls_200";
}
if (&bondif($i,6,2)) {
$type[$i] = "opls_202";
}
if (&bondif($i,16,1)) {
$type[$i] = "opls_203";
}
}
if ($valence[$i] == 3) {
if (&bondif($i,8,1)) {
$type[$i] = "opls_496";
}
}
if ($valence[$i] == 4) {
if (&bondif($i,8,2,6,2) or &bondif($i,8,3,6,1)) {
$type[$i] = "opls_493";
}
if (&bondif($i,8,2,7,1)) {
$type[$i] = "opls_474";
}
}
}
if ($Z == 17) {
$type[$i] = "opls_151";
}
if ($Z == 36) {
$type[$i] = "opls_722";
}
}
for ($i = 1; $i <= $linha; $i++) {
if ($Z[$i] == 15) {
if (&bondif($i,8,4) and $valence[$i] == 4) {
@list = split(/:/, $bond_list[$i]);
$c=0;
$phosp[0][1] = "opls_445";
$phosp[0][2] = "opls_440";
$phosp[0][3] = "opls_440";
$phosp[1][1] = "opls_446";
$phosp[1][2] = "opls_441";
$phosp[1][3] = $phosp[1][2];
$phosp[2][1] = "opls_447";
$phosp[2][2] = "opls_442";
$phosp[2][3] = $phosp[2][2];
foreach $atom (@list) {
if (&bondif($atom,6,1)) {
$c++;
}
}
foreach $atom (@list) {
if (&bondif($atom,6,1)) {
$type[$atom] = $phosp[2][$c];
}
else {
$type[$atom] = $phosp[1][$c];
}
if (&bondif($atom,1,1)) {
$type[$atom] = "opls_154";
}
}
$type[$i] = $phosp[0][$c];
}
if (&bondif($i,8,3,6,1) and $valence[$i] == 4) {
$type[$i] = "opls_450";
@list = split(/:/, $bond_list[$i]);
foreach $atom (@list) {
if (&bondif($atom,6,1) and $Z[$atom] == 8) {
$type[$atom] = "opls_452";
}
elsif ($Z[$atom] == 6) {
$type[$atom] = "opls_455";
}
else {
$type[$atom] = "opls_451";
}
}
}
}
}
for ($i = 1; $i <= $linha; $i++) {
@list = split(/:/, $bond_list[$i]);
if ($Z[$i] == 6) {
if ($valence[$i] == 4) {
foreach $atom (@list) {
if ($type[$atom] eq "opls_238" and $type[$i] !~ /opls/) {
foreach $atom2 (@list) {
if ($type[$atom2] eq "opls_235") {
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_223B"; }
if (&bondif($i,6,2,1,1) or &bondif($i,6,3)) {$type[$i] = "opls_224B";}
}
}
if ($type[$i] !~ /opls/) {
if (&bondif($i,1,3)) {$type[$i] = "opls_242";}
if (&bondif($i,1,2,6,1) or &bondif($i,1,1,6,2) or &bondif($i,6,3)) {$type[$i] = "opls_244";}
}
}
if ($type[$atom] eq "opls_239") {
if (&bondif($i,1,3)) {$type[$i] = "opls_243";}
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_245";}
if (&bondif($i,6,2,1,1) or &bondif($i,6,3)) {$type[$i] = "opls_246";}
}
if ($type[$atom] eq "opls_900") {
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_906";}
if (&bondif($i,1,3)) {$type[$i] = "opls_903";}
}
if ($type[$atom] eq "opls_901") {
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_907";}
if (&bondif($i,1,3)) {$type[$i] = "opls_904";}
}
if ($type[$atom] eq "opls_902") {
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_908";}
if (&bondif($i,1,3)) {$type[$i] = "opls_905";}
}
if ($type[$atom] eq "opls_940") {
if (&bondif($i,6,3)) {$type[$i] = "opls_945";}
if (&bondif($i,6,2,1,1)) {$type[$i] = "opls_944";}
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_943";}
if (&bondif($i,1,3)) {$type[$i] = "opls_942";}
}
if ($type[$atom] eq "opls_442") {$type[$i] = "opls_443";}
if ($type[$atom] eq "opls_447") {$type[$i] = "opls_448";}
if ($type[$atom] eq "opls_760") {
if (&bondif($i,1,3)) {$type[$i] = "opls_762";}
if (&bondif($i,1,2)) {$type[$i] = "opls_765";}
if (&bondif($i,1,1)) {$type[$i] = "opls_766";}
}
if ($type[$atom] eq "opls_474") {$type[$i] = "opls_476";}
if ($type[$atom] eq "opls_480") {
if (&bondif($i,1,3)) {$type[$i] = "opls_482";}
else {$type[$i] = "opls_484";}
}
if ($type[$atom] eq "opls_754") {
if (&bondif($i,6,4)) {$type[$i] = "opls_758";}
if (&bondif($i,6,3,1,1)) {$type[$i] = "opls_757";}
if (&bondif($i,6,2,1,2)) {$type[$i] = "opls_756";}
if (&bondif($i,6,1,1,3)) {$type[$i] = "opls_755";}
}
}
}
if ($valence[$i] == 3) {
if (&bondif($i,6,3)) {$type[$i] = "opls_141";}
for ($k = 9; $k <= 50; $k++) {
if (&bondif($i,$k,1) and $valence[$k] > 1) {
if (&bondif($i,1,1)) {$type[$i] = "opls_142";}
else {$type[$i] = "opls_141";}
}
}
if (&bondif($i,6,1,1,1,17,1)) {$type[$i] = "opls_227";}
if (&bondif($i,6,2,1,1)) {$type[$i] = "opls_142";}
if (&bondif($i,6,1,1,2)) {$type[$i] = "opls_143";}
$acid=0;
if (&bondif($i,8,2,6,1) or &bondif($i,8,3)) {
$acid=1;
}
foreach $atom (@list) {
if ($type[$atom] eq "opls_281" and $type[$i] ne "opls_267" and $type[$i] ne "opls_465") {$type[$i] = "opls_280";}
if ($type[$atom] eq "opls_278") {$type[$i] = "opls_277";}
if ($acid == 1) {
if ($valence[$atom] == 2 and $Z[$atom] == 8) {
$acid++;
@array = split(/:/, $bond_list[$atom]);
foreach $atom2 (@array) {
if ($atom2 != $i) {
if ($Z[$atom2] == 1) {
$type[$i] = "opls_267";
$type[$atom] = "opls_268";
$type[$atom2] = "opls_270";
}
if ($Z[$atom2] == 6) {
$type[$i] = "opls_465";
$type[$atom] = "opls_467";
$type[$atom2] = "opls_468";
}
}
}
}
}
}
if ($acid == 1) {$type[$i] = "opls_271";}
}
}
}
for ($i = 1; $i <= $linha; $i++) {
if ($Z[$i] == 6 and $valence[$i] == 4) {
$k=0;
$H=0;
@array = &splitb($i);
foreach $atom (@array) {
if ($Z[$atom] == 8 and $valence[$atom] == 2) {
$k++;
}
if ($Z[$atom] == 1) {
$H++;
}
}
if ($k == 2) {
$hemi=0;
foreach $atom (@array) {
if ($Z[$atom] == 8) {
@array2 = &splitb($atom);
foreach $atom2 (@array2) {
if ($Z[$atom2] == 1) {
$hemi = 1;
$type[$atom] = "opls_187";
$type[$atom2] = "opls_188";
if ($H == 0) {$type[$i] = "opls_198";}
if ($H == 1) {$type[$i] = "opls_195";}
if ($H == 2) {$type[$i] = "opls_191";}
}
if ($Z[$atom2] == 6 and $atom2 != $i) {$type[$atom] = "opls_186";}
}
}
}
if ($hemi == 0) {
if ($H == 0) {$type[$i] = "opls_197";}
if ($H == 0) {$type[$i] = "opls_193";}
if ($H == 0) {$type[$i] = "opls_189";}
}
foreach $atom (@array) {
if ($H == 1 and $Z[$atom] == 1) {
if ($hemi == 1) {$type[$atom] = "opls_196";}
else {$type[$atom] = "opls_194";}
}
if ($H == 2 and $Z[$atom] == 1) {
if ($hemi == 1) {$type[$atom] = "opls_192";}
else {$type[$atom] = "opls_190";}
}
}
}
}
}
$A=1;
$D=1;
$P=1;
$B=1;
for ($i = 1; $i <= $linha; $i++) {
if ($Z[$i] != 1) {
if ($Z[$i] == 6) {
if ($valence[$i] == 3 and $type[$i] ne "opls_145" and $type[$i] ne "opls_145B") {
if (&ring(0,6,$i,3)) {
for ($k = 0; $k < 6; $k++) {
$array2[$k] = $array_r[$k];
}
for ($k = 0; $k < 6; $k++) {
$type[$array2[$k]] = "opls_145";
@list = split(/:/, $bond_list[$array2[$k]]);
foreach $atom (@list) {
$ok=1;
for ($j = 0; $j < 6; $j++) {
if ($atom == $array2[$j]) {
$ok=0;
}
}
if ($ok == 1 and &ring(0,6,$atom,3)) {$type[$array2[$k]] = "opls_145B";}
}
}
}
if (&ring(0,10,$i,3)) {
for ($k = 0; $k < 10; $k++) {
$type[$array_r[$k]] = "opls_145";
}
for ($k = 0; $k < 10; $k++) {
$ring_bond=0;
@list = split(/:/, $bond_list[$array_r[$k]]);
foreach $atom (@list) {
for ($j = 0; $j < 10; $j++) {
if ($atom == $array_r[$j]) {
$ring_bond++;
if ($ring_bond == 3) {$type[$array_r[$k]] = "opls_147";}
}
}
}
}
}
if (&ring(0,14,$i,3)) {
for ($k = 0; $k < 14; $k++) {
$type[$array_r[$k]] = "opls_145";
}
}
}
if ($valence[$i] == 4) {
if (&ring(0,3,$i,4)) {
for ($k = 0; $k < 3; $k++) {
if ($bond[$array_r[$k]][1] == 2) {$type[$array_r[$k]] = "opls_711";}
if ($bond[$array_r[$k]][1] == 1) {$type[$array_r[$k]] = "opls_712";}
if ($bond[$array_r[$k]][1] == 0) {$type[$array_r[$k]] = "opls_713";}
}
}
else {
$ring[$i][3]=1;
}
}
}
if ($Z[$i] == 7 and $purine[$i] != 1) {
if (&ring(0,6,$i,3) and $valence[$i] == 2) {
$type[$i] = "opls_520";
$type[$array_r[1]] = "opls_521";
$type[$array_r[2]] = "opls_522";
$type[$array_r[3]] = "opls_523";
$type[$array_r[4]] = "opls_522";
$type[$array_r[5]] = "opls_521";
}
if (&ring(0,6,$i,3,3,7)) {
$type[$i] = "opls_527";
$type[$array_r[1]] = "opls_528";
$type[$array_r[2]] = "opls_528";
$type[$array_r[3]] = "opls_527";
$type[$array_r[4]] = "opls_528";
$type[$array_r[5]] = "opls_528";
}
if (&ring(0,5,$i,3,2,8)) {
$type[$i] = "opls_573";
$type[$array_r[1]] = "opls_572";
$type[$array_r[2]] = "opls_571";
$type[$array_r[3]] = "opls_575";
$type[$array_r[4]] = "opls_574";
}
if (&ring(0,5,$i,3,1,8)) {
$type[$i] = "opls_580";
$type[$array_r[1]] = "opls_579";
$type[$array_r[2]] = "opls_583";
$type[$array_r[3]] = "opls_582";
$type[$array_r[4]] = "opls_581";
}
if ($valence[$i] == 3) {
if (&ring(0,5,$i,0,1,7)) {
$type[$i] = "opls_548";
$type[$array_r[1]] = "opls_549";
}
if (&ring(0,5,$i,3,1,7)) {
$type[$i] = "opls_548";
$type[$array_r[1]] = "opls_549";
$type[$array_r[2]] = "opls_550";
$type[$array_r[3]] = "opls_551";
$type[$array_r[4]] = "opls_552";
}
if (&ring(0,5,$i,3,2,7) and $type[$i] ne "opls_354" and $type[$i] ne "opls_628") {
$type[$i] = "opls_557";
$type[$array_r[1]] = "opls_558";
$type[$array_r[2]] = "opls_559";
$type[$array_r[3]] = "opls_560";
$type[$array_r[4]] = "opls_561";
}
if (&ring(0,5,$i,3)) {
$type[$i] = "opls_542";
$type[$array_r[1]] = "opls_543";
$type[$array_r[2]] = "opls_544";
$type[$array_r[3]] = "opls_544";
$type[$array_r[4]] = "opls_543";
}
}
if (&ring(0,6,$i,3,2,7) and $type[$i] ne "opls_321" and $type[$i] ne "opls_335") {
$type[$i] = "opls_530";
$type[$array_r[1]] = "opls_531";
$type[$array_r[2]] = "opls_530";
$type[$array_r[3]] = "opls_532";
$type[$array_r[4]] = "opls_533";
$type[$array_r[5]] = "opls_532";
if (&bondif($array_r[2],1,1) and &bondif($array_r[3],8,1) and &bondif($array_r[1],8,1)) {
$type[$i] = "opls_319";
$type[$array_r[1]] = "opls_320";
$type[$array_r[2]] = "opls_321";
$type[$array_r[3]] = "opls_322";
$type[$array_r[4]] = "opls_323";
$type[$array_r[5]] = "opls_324";
}
if ($valence[$array_r[2]] == 2 and &bondif($array_r[3],7,2) and &bondif($array_r[1],8,1)) {
$type[$i] = "opls_333";
$type[$array_r[1]] = "opls_334";
$type[$array_r[2]] = "opls_335";
$type[$array_r[3]] = "opls_336";
$type[$array_r[4]] = "opls_337";
$type[$array_r[5]] = "opls_338";
}
}
if (&ring(0,9,$i,3,2,7,4,7,6,7)) {
if ($valence[$array_r[4]] == 3) {
for ($k = 0; $k <= 9; $k++) {
$purine[$array_r[$k]] = 1;
}
if (&bondif($array_r[8],1,1)) {
$type[$i] = "opls_620";
$type[$array_r[1]] = "opls_621";
$type[$array_r[2]] = "opls_622";
$type[$array_r[3]] = "opls_623";
$type[$array_r[4]] = "opls_628";
$type[$array_r[5]] = "opls_627";
$type[$array_r[6]] = "opls_626";
$type[$array_r[7]] = "opls_624";
$type[$array_r[8]] = "opls_625";
}
if (&bondif($array_r[8],8,1)) {
$type[$i] = "opls_361";
$type[$array_r[1]] = "opls_362";
$type[$array_r[2]] = "opls_363";
$type[$array_r[3]] = "opls_364";
$type[$array_r[4]] = "opls_354";
$type[$array_r[5]] = "opls_353";
$type[$array_r[6]] = "opls_352";
$type[$array_r[7]] = "opls_365";
$type[$array_r[8]] = "opls_366";
}
if (&bondif($array_r[8],7,2)) {
$type[$i] = "opls_346";
$type[$array_r[1]] = "opls_347";
$type[$array_r[2]] = "opls_348";
$type[$array_r[3]] = "opls_349";
$type[$array_r[4]] = "opls_354";
$type[$array_r[5]] = "opls_353";
$type[$array_r[6]] = "opls_352";
$type[$array_r[7]] = "opls_350";
$type[$array_r[8]] = "opls_351";
}
}
}
}
if ($Z[$i] == 16) {
if (&ring(0,5,$i,3,2,7)) {
$type[$i] = "opls_633";
$type[$array_r[1]] = "opls_634";
$type[$array_r[2]] = "opls_635";
$type[$array_r[3]] = "opls_636";
$type[$array_r[4]] = "opls_637";
}
}
}
}
for ($i = 1; $i <= $linha; $i++) {
if ($Z[$i] == 7 and $valence[$i] == 2) {
$array_r[0]=$i;
if (&ring(0,10,$i,3)) {
$type[$i] = "opls_603";
for ($k = 0; $k <= 10; $k++) {
$list[$k]=$array_r[$k];
}
$array_r[0]=$list[1];
if(&ring(0,6,$array_r[0],3)) {
for ($k = 0; $k <= 10; $k++) {
$array_r[0+$k]=$list[10-$k];
}
}
else {
for ($k = 0; $k <= 10; $k++) {
$array_r[$k]=$list[$k];
}
}
$type[$array_r[1]] = "opls_604";
$type[$array_r[2]] = "opls_605";
$type[$array_r[3]] = "opls_606";
$type[$array_r[4]] = "opls_612";
$type[$array_r[5]] = "opls_607";
$type[$array_r[6]] = "opls_608";
$type[$array_r[7]] = "opls_609";
$type[$array_r[8]] = "opls_610";
$type[$array_r[9]] = "opls_611";
}
}
}
for ($i = 1; $i <= $linha; $i++) {
$j = $bond_list[$i];
if ($Z[$i] == 1) {
if ($type[$j] eq "opls_145") {$type[$i] = "opls_146";}
if ($type[$j] eq "opls_142") {$type[$i] = "opls_144";}
if ($type[$j] eq "opls_143") {$type[$i] = "opls_144";}
if ($type[$j] eq "opls_154") {$type[$i] = "opls_155";}
if ($type[$j] eq "opls_287") {$type[$i] = "opls_290";}
if ($type[$j] eq "opls_940") {$type[$i] = "opls_941";}
if ($type[$j] eq "opls_309") {$type[$i] = "opls_310";}
if ($type[$j] eq "opls_238") {$type[$i] = "opls_241";}
if ($type[$j] eq "opls_237") {$type[$i] = "opls_240";}
if ($type[$j] eq "opls_900") {$type[$i] = "opls_909";}
if ($type[$j] eq "opls_901") {$type[$i] = "opls_910";}
if ($type[$j] eq "opls_542") {$type[$i] = "opls_545";}
if ($type[$j] eq "opls_543") {$type[$i] = "opls_546";}
if ($type[$j] eq "opls_544") {$type[$i] = "opls_547";}
if ($type[$j] eq "opls_604") {$type[$i] = "opls_613";}
if ($type[$j] eq "opls_605") {$type[$i] = "opls_614";}
if ($type[$j] eq "opls_606") {$type[$i] = "opls_615";}
if ($type[$j] eq "opls_607") {$type[$i] = "opls_616";}
if ($type[$j] eq "opls_608") {$type[$i] = "opls_617";}
if ($type[$j] eq "opls_609") {$type[$i] = "opls_618";}
if ($type[$j] eq "opls_610") {$type[$i] = "opls_619";}
if ($type[$j] eq "opls_169") {$type[$i] = "opls_170";}
if ($type[$j] eq "opls_171") {$type[$i] = "opls_172";}
if ($type[$j] eq "opls_249") {$type[$i] = "opls_250";}
if ($type[$j] eq "opls_443") {$type[$i] = "opls_444";}
if ($type[$j] eq "opls_277") {$type[$i] = "opls_279";}
if ($type[$j] eq "opls_762") {$type[$i] = "opls_763";}
if ($type[$j] eq "opls_765") {$type[$i] = "opls_763";}
if ($type[$j] eq "opls_766") {$type[$i] = "opls_763";}
if ($type[$j] eq "opls_581") {$type[$i] = "opls_584";}
if ($type[$j] eq "opls_582") {$type[$i] = "opls_585";}
if ($type[$j] eq "opls_583") {$type[$i] = "opls_586";}
if ($type[$j] eq "opls_476") {$type[$i] = "opls_477";}
if ($type[$j] eq "opls_478") {$type[$i] = "opls_479";}
if ($type[$j] eq "opls_480") {$type[$i] = "opls_481";}
if ($type[$j] eq "opls_482") {$type[$i] = "opls_483";}
if ($type[$j] eq "opls_484") {$type[$i] = "opls_485";}
if ($type[$j] eq "opls_548") {$type[$i] = "opls_553";}
if ($type[$j] eq "opls_550") {$type[$i] = "opls_554";}
if ($type[$j] eq "opls_551") {$type[$i] = "opls_555";}
if ($type[$j] eq "opls_552") {$type[$i] = "opls_556";}
if ($type[$j] eq "opls_521") {$type[$i] = "opls_524";}
if ($type[$j] eq "opls_522") {$type[$i] = "opls_525";}
if ($type[$j] eq "opls_523") {$type[$i] = "opls_526";}
if ($type[$j] eq "opls_634") {$type[$i] = "opls_638";}
if ($type[$j] eq "opls_636") {$type[$i] = "opls_639";}
if ($type[$j] eq "opls_637") {$type[$i] = "opls_640";}
if ($type[$j] eq "opls_523") {$type[$i] = "opls_526";}
if ($type[$j] eq "opls_528") {$type[$i] = "opls_529";}
if ($type[$j] eq "opls_531") {$type[$i] = "opls_534";}
if ($type[$j] eq "opls_532") {$type[$i] = "opls_535";}
if ($type[$j] eq "opls_533") {$type[$i] = "opls_536";}
if ($type[$j] eq "opls_157") {$type[$i] = "opls_156";}
if ($type[$j] eq "opls_200") {$type[$i] = "opls_204";}
if ($type[$j] eq "opls_572") {$type[$i] = "opls_576";}
if ($type[$j] eq "opls_574") {$type[$i] = "opls_577";}
if ($type[$j] eq "opls_575") {$type[$i] = "opls_578";}
if ($type[$j] eq "opls_321") {$type[$i] = "opls_327";}
if ($type[$j] eq "opls_323") {$type[$i] = "opls_239";}
if ($type[$j] eq "opls_324") {$type[$i] = "opls_330";}
if ($type[$j] eq "opls_319") {$type[$i] = "opls_325";}
if ($type[$j] eq "opls_333") {$type[$i] = "opls_339";}
if ($type[$j] eq "opls_337") {$type[$i] = "opls_344";}
if ($type[$j] eq "opls_338") {$type[$i] = "opls_345";}
if ($type[$j] eq "opls_557") {$type[$i] = "opls_562";}
if ($type[$j] eq "opls_558") {$type[$i] = "opls_563";}
if ($type[$j] eq "opls_560") {$type[$i] = "opls_564";}
if ($type[$j] eq "opls_561") {$type[$i] = "opls_565";}
if ($type[$j] eq "opls_361") {$type[$i] = "opls_367";}
if ($type[$j] eq "opls_347") {$type[$i] = "opls_355";}
if ($type[$j] eq "opls_353") {$type[$i] = "opls_359";}
if ($type[$j] eq "opls_354") {$type[$i] = "opls_360";}
if ($type[$j] eq "opls_621") {$type[$i] = "opls_629";}
if ($type[$j] eq "opls_625") {$type[$i] = "opls_630";}
if ($type[$j] eq "opls_627") {$type[$i] = "opls_631";}
if ($type[$j] eq "opls_628") {$type[$i] = "opls_632";}
}
if ($Z[$i] == 17) {
if ($type[$j] eq "opls_145") { $type[$i] = "opls_264"; $type[$j] = "opls_263"; }
if ($type[$j] eq "opls_227") { $type[$i] = "opls_226"; }
if ($Z[$j] == 6 and $valence[$j] == 3 and $type[$i] !~ /opls/) { $type[$i] = "opls_264";}
}
if ($Z[$i] == 9) {
if ($type[$j] eq "opls_145") { $type[$j] = "opls_718"; $type[$i] = "opls_719";}
if ($type[$j] eq "opls_961" or $type[$j] eq "opls_962") {$type[$i] = "opls_965"}
if ($type[$i] !~ /opls/ and $Z[$j] == 6) {
@array = split(/:/, $bond_list[$j]);
$type[$i] = "opls_956";
$h=0;
foreach $atom (@array) {
if ($Z[$atom] == 1) {
$h++;
$type[$atom] = "opls_958";
}
}
if ($h == 0) {$type[$j] = "opls_960";}
if ($h == 1) {$type[$j] = "opls_959";}
if ($h == 2) {$type[$j] = "opls_957";}
}
}
if ($Z[$i] == 17) {
if ($type[$j] eq "opls_145") {$type[$i] = "opls_264";$type[$j] = "opls_263";}
}
if ($Z[$i] == 36) {
if ($type[$j] eq "opls_145") {$type[$i] = "opls_730";$type[$j] = "opls_729";}
}
if ($Z[$i] == 53) {
if ($type[$j] eq "opls_145") {$type[$i] = "opls_732";$type[$j] = "opls_731";}
}
@array = &splitb($i);
foreach $atom (@array) {
if ($Z[$i] == 6) {
if ($type[$atom] eq "opls_145") {
if (&bondif($i,6,1,1,3) and $type[$i] eq "opls_135") {$type[$i] = "opls_148";}
if (&bondif($i,6,2,1,2) and $type[$i] eq "opls_136") {$type[$i] = "opls_149";}
if (&bondif($i,6,3,1,1) and $type[$i] eq "opls_137") {$type[$i] = "opls_515";}
if (&bondif($i,6,4) and $type[$i] eq "opls_139") {$type[$i] = "opls_515";}
if ($type[$i] eq "opls_267") {$type[$i] = "opls_470";}
if ($type[$i] eq "opls_754") {$type[$i] = "opls_261";$type[$atom] = "opls_260";}
foreach $atom2 (@array) {
if ($type[$atom2] eq "opls_154") {
if (&bondif($i,1,2)) {$type[$i] = "opls_218";}
if (&bondif($i,1,1)) {$type[$i] = "opls_219";}
if (&bondif($i,1,0)) {$type[$i] = "opls_220";}
}
if ($type[$atom2] eq "opls_753") {$type[$atom2] = "opls_262";}
}
}
if ($type[$atom] eq "opls_277" or $type[$atom] eq "opls_280") {
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {$type[$atom2] = "opls_282";}
}
}
if ($type[$atom] eq "opls_474" and $type[$i] eq "opls_145") {$type[$i] = "opls_488"; }
if ($type[$atom] eq "opls_200") {
if (&bondif($i,1,3)) {$type[$i] = "opls_217";}
if (&bondif($i,1,2)) {$type[$i] = "opls_206";}
if (&bondif($i,1,1)) {$type[$i] = "opls_207";}
if (&bondif($i,1,0)) {$type[$i] = "opls_208";}
}
if ($type[$atom] eq "opls_202" and $valence[$i] == 4) {
if (&bondif($i,1,3)) {$type[$i] = "opls_209";}
if (&bondif($i,1,2)) {$type[$i] = "opls_210";}
if (&bondif($i,1,1)) {$type[$i] = "opls_211";}
if (&bondif($i,1,0)) {$type[$i] = "opls_212";}
}
if ($type[$atom] eq "opls_203") {
if (&bondif($i,1,3)) {$type[$i] = "opls_213";}
if (&bondif($i,1,2)) {$type[$i] = "opls_214";}
if (&bondif($i,1,1)) {$type[$i] = "opls_215";}
if (&bondif($i,1,0)) {$type[$i] = "opls_216";}
}
if ($type[$atom] eq "opls_323") {
$type[$i] = "opls_331";
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {$type[$atom2] = "opls_332";}
}
}
if ($type[$atom] eq "opls_151" and $valence[$i] == 4) {
$type[$i] = "opls_152";
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {$type[$atom2] = "opls_153";}
}
}
if ($type[$atom] eq "opls_271") {
if (&bondif($i,1,2,6,1)) {
foreach $atom2 (@array) {
if ($type[$atom2] eq "opls_238") {$type[$i] = "opls_284";}
}
}
if (&bondif($i,1,1,6,2)) {
foreach $atom2 (@array) {
if ($type[$atom2] eq "opls_238") {
$type[$i] = "opls_283";
if (&ring(0,$i,5,4,1,7)) {$type[$i] = "opls_285";}
}
}
}
}
if ($type[$atom] eq "opls_287") {
if (&bondif($i,1,2,6,1)) {
$type[$i] = "opls_292";
foreach $atom2 (@array) {
if ($type[$atom2] eq "opls_271") {$type[$i] = "opls_298";}
if ($type[$atom2] eq "opls_235") {$type[$i] = "opls_292B";}
}
}
if (&bondif($i,1,1,6,2)) {
$type[$i] = "opls_293";
foreach $atom2 (@array) {
if ($type[$atom2] eq "opls_271") {$type[$i] = "opls_299";}
if ($type[$atom2] eq "opls_235") {
$type[$i] = "opls_293B";
if (&ring(0,$i,5,4,1,7)) {
$type[$i] = "opls_295";
$type[$array_r[2]] = "opls_296";
}
}
}
}
if (&bondif($i,1,3)) {$type[$i] = "opls_291";}
}
}
if ($Z[$i] == 7) {
if ($type[$atom] eq "opls_247") {
$type[$i] = "opls_249";
foreach $atom2 (@array) {
if ($Z[$$atom2] == 1) {$type[$atom2] = "opls_250";}
}
}
if ($type[$atom] eq "opls_145" and $type[$i] eq "opls_760") {
$type[$i] = "opls_767";
$type[$atom] = "opls_768";
}
if ($type[$atom] eq "opls_336" and $type[$i] ne "opls_335") {
$type[$i] = "opls_341";
@array_atom = &splitb($atom);
foreach $atom2 (@array_atom) {
if ($Z[$atom2] == 6) {
$C5 = $atom2;
}
if ($Z[$atom2] == 7 and $atom2 != $i) {
$N3 = $atom2;
}
}
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {
if ($dist[$atom2][$C5] <= $dist[$atom2][$N3]) {
$type[$atom2] = "opls_343";
}
else {
$type[$atom2] = "opls_342";
}
}
}
}
if ($type[$atom] eq "opls_362" and $purine[$i] != 1) {
$type[$i] = "opls_368";
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {$type[$atom2] = "opls_369";}
}
}
if ($type[$atom] eq "opls_351" and $purine[$i] != 1) {
$type[$i] = "opls_356";
@array_atom = &splitb($atom);
foreach $atom2 (@array_atom) {
if ($Z[$atom2] == 6) {
$C5 = $atom2;
}
if ($Z[$atom2] == 7 and $atom2 != $i) {
$N1 = $atom2;
}
}
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {
if ($dist[$atom2][$C5] <= $dist[$atom2][$N1]) {
$type[$atom2] = "opls_358";
}
else {
$type[$atom2] = "opls_357";
}
}
}
}
}
if ($Z[$i] == 8) {
if ($type[$atom] eq "opls_145") {
if ($type[$i] eq "opls_154") {
$type[$i] = "opls_167";
foreach $atom2 (@array) {
if ($Z[$atom2] == 6) {
$type[$atom2] = "opls_166";
}
if ($Z[$atom2] == 1) {
$type[$atom2] = "opls_168";
}
}
}
if (&bondif($i,6,1,1,0)) {
$type[$i] = "opls_179";
}
}
if ($type[$atom] eq "opls_247") {
$type[$i] = "opls_248";
}
if ($type[$atom] eq "opls_271") {
$type[$i] = "opls_272";
}
if ($type[$atom] eq "opls_267" and $valence[$i] == 1) {
$type[$i] = "opls_269";
}
if ($type[$atom] eq "opls_465" and $valence[$i] == 1) {
$type[$i] = "opls_466";
}
if ($type[$atom] eq "opls_493" and $valence[$i] == 1) {
$type[$i] = "opls_494";
}
if ($type[$atom] eq "opls_474") {
$type[$i] = "opls_475";
}
if ($type[$atom] eq "opls_767" or $type[$atom] eq "opls_760") {
$type[$i] = "opls_761";
}
if ($type[$atom] eq "opls_496") {
$type[$i] = "opls_497";
@array2 = split (/:/, $bond_list[$atom]);
foreach $atom2 (@array2) {
if ($Z[$atom2] == 6) {
if (&bondif($atom2,1,3)) {
$type[$atom2] = "opls_498";
}
if (&bondif($atom2,1,2,6,1)) {
$type[$atom2] = "opls_499";
}
}
}
}
if ($type[$atom] eq "opls_320") {$type[$i] = "opls_326";}
if ($type[$atom] eq "opls_322") {$type[$i] = "opls_328";}
if ($type[$atom] eq "opls_334") {$type[$i] = "opls_340";}
}
if ($Z[$i] == 16) {
if ($type[$atom] eq "opls_145") {
if ($valence[$i] == 2) {
if (&bondif($i,6,2)) {
$type[$i] = "opls_222";
$type[$atom] = "opls_228";
}
if (&bondif($i,6,1,1,1)) {
$type[$i] = "opls_734";
$type[$atom] = "opls_735";
foreach $atom2 (@array) {
if ($Z[$atom2] == 1) {$type[$atom2] = "opls_204";}
}
}
}
if ($type[$i] eq "opls_474") {$type[$atom] = "opls_488";}
}
}
}
}
for ($i = 1; $i <= $linha; $i++) {
$BO_ene[$i] = 0;
$ene[$i] = 0;
if ($type[$i] eq "opls_141") {$ene[$i] = 3;}
if ($type[$i] eq "opls_142") {$ene[$i] = 2;}
if ($type[$i] eq "opls_143") {$ene[$i] = 1;}
}
for ($i = 1; $i <= $linha; $i++) {
if ($ene[$i] >= 1) {
@array = &splitb($i);
foreach $atom (@array) {
if ($ene[$atom] == 0) {
$BO[$i][$atom] = 1;
$BO[$atom][$i] = 1;
}
if ($ene[$atom] >= 1) {
$BO_ene[$i]++;
}
}
if ($BO_ene[$i] == 1) {
foreach $atom (@array) {
if ($ene[$atom] >= 1) {
$BO[$i][$atom] = 2;
$BO[$atom][$i] = 2;
}
}
}
}
}
$kill = 0;
$k = 0;
while ($kill == 0) {
$ok = 1;
$k++;
for ($i = 1; $i <= $linha; $i++) {
$assign=0;
if ($BO_ene[$i] >= 2) {
@array = &splitb($i);
if ($BO_ene[$i] == 2) {
foreach $atom (@array) {
if ($ene[$atom] >= 1 and $BO[$i][$atom] == 2) {
$assign=1;
}
if ($ene[$atom] >= 1 and $BO[$i][$atom] == 1) {
$assign=2;
}
}
}
if ($BO_ene[$i] == 3) {
foreach $atom (@array) {
if ($ene[$atom] >= 1 and $BO[$i][$atom] == 2) {
$assign = 1;
}
}
}
if ($assign) {
foreach $atom (@array) {
if ($ene[$atom] >= 1 and $BO[$i][$atom] == 0) {
if ($assign == 1) {
$BO[$i][$atom] = 1;
$BO[$atom][$i] = 1;
if ($ene[$i] == 2 and $ene[$atom] == 2) {
$type[$i] = "opls_150";
$type[$atom] = "opls_150";
}
if ($ene[$i] == 3 and $ene[$atom] == 3) {
$type[$i] = "opls_178";
$type[$atom] = "opls_178";
}
}
if ($assign == 2) {
$BO[$i][$atom] = 2;
$BO[$atom][$i] = 2;
}
}
}
}
$sum=0;
foreach $atom (@array) {
$sum = ($sum + $BO[$i][$atom]);
}
if ($sum != 4) {
$ok = 0;
}
}
}
if ($ok == 1 or $k > 50) {
$kill = 1;
}
}
for ($i = 1; $i <= $linha; $i++) {
if ($type[$i] !~ /./) {
if ($Z[$i] == 1) {$type[$i] = "opls_140";}
if ($Z[$i] == 6) {
if ($valence[$i] == 4) {$type[$i] = "opls_135";}
if ($valence[$i] == 3) {$type[$i] = "opls_145";}
}
if ($Z[$i] == 7) {$type[$i] = "opls_900";}
if ($Z[$i] == 8) {
if (&bondif($i,1,1)) {$type[$i] = "opls_154";}
if (&bondif($i,1,0,6,1)) {$type[$i] = "opls_180";}
if (&bondif($i,15,1) or &bondif($i,15,2)) {$type[$i] = "opls_441";}
if (&bondif($i,16,1)) {$type[$i] = "opls_496";}
}
if ($Z[$i] == 14) {$type[$i] = "SI";}
if ($Z[$i] == 15) {$type[$i] = "opls_440";}
if ($Z[$i] == 16) {
if (&bondif($i,1,1)) {$type[$i] = "opls_200";}
elsif (&bondif($i,8,1) or &bondif($i,8,2) or &bondif($i,8,3) or &bondif($i,8,4)) {
$type[$i] = "opls_497";
}
else {
$type[$i] = "opls_202";
}
}
}
}
@defgroup = ('opls_474','opls_493','opls_496','opls_393','opls_440','opls_445','opls_450','opls_781');
for ($i = 1; $i <= $linha; $i++) {
foreach $group (@defgroup) {
if ($type[$i] eq $group) {
$makeg[$i] = 1;
$group[$i] = $GROUP;
$GROUP++;
}
}
}
for ($i = 1; $i <= $linha; $i++) {
if ($Z[$i] != 6 and $makeg[$i] != 1) {
$valenceg=10;
foreach (&splitb($i)) {
if ($makeg[$_] == 1) {
$group[$i] = $group[$_];
last;
}
if ($Z[$_] == 6 and $valence[$_] < $valenceg) {
$valenceg = $valence[$_];
$group[$i] = $group[$_];
}
}
}
}
for ($i = 1; $i <= $linha; $i++) {
if ($group[$i] !~ /\d/) {
foreach (&splitb($i)) {
$group[$i] = $group[$_];
}
}
}
for ($i = 1; $i <= $linha; $i++) {
print "|$i $type[$i] $group[$i]";
}
sub bondif {
my $i = $_[0];
my $ok=1;
my $j;
for ($j = 1; $j <= @_; $j++) {
if (int($j/2) != ($j/2)) {
$a=$_[$j];
$b=$_[$j+1];
if ($bond[$i][$a] != $b and $b =~ /\d/) {
$ok = 0;
}
}
}
return $ok;
}
sub ring {
my $j = $_[0];
my $R = $_[1];
my $i = $_[2];
my $valence = $_[3];
my $m = $_[4];
my $n = $_[5];
my $o = $_[6];
my $p = $_[7];
my $q = $_[8];
my $r = $_[9];
my $k;
my $gone=0;
my @atoms;
my @F;
my $a;
my $return;
my $var;
my @list;
my $atom;
if ($j == 0) {
$array_r[0] = $i;
}
if ($j == $R and $array_r[$R] == $i) {
return 1;
}
for ($k = $R; $k > $j; $k--) {
$array_r[$k]=0;
}
$go_j=0;
if ($n > 0) {
if ($j == $m) {
if ($Z[$array_r[$j]] != $n) {
return 0;
}
else {
$go_j = 1;
}
}
}
if ($o > 0) {
if ($j == $o) {
if ($Z[$array_r[$j]] != $p) {
return 0;
}
else {
$go_j = 1;
}
}
}
if ($q > 0) {
if ($j == $q) {
if ($Z[$array_r[$j]] != $r) {
return 0;
}
else {
$go_j = 1;
}
}
}
if (($Z[$array_r[$j]] == 6 and ($valence[$array_r[$j]] == $valence or $valence == 0)) or $j == 0 or $go_j == 1) {
@list = split(/:/, $bond_list[$array_r[$j]]);
$k=0;
foreach $atom (@list) {
unless ($Z[$atom] == 1 or $ring[$atom][$R] == 1) {
$atoms[$k][$j] = $atom;
$k++;
}
}
$F[$j]=($k-1);
for ($k = 0; $k <= $F[$j]; $k++) {
$ok=1;
for ($a = 1; $a < $j; $a++) {
if ($array_r[$a] == $atoms[$k][$j]) {
$ok=0;
}
}
if ($ok == 1) {
$array_r[$j+1]=$atoms[$k][$j];
$gone++;
$var = &ring(($j+1),$R,$i,$valence,$m,$n,$o,$p,$q,$r);
if ($var == 1) {
return $var;
last;
}
}
}
}
if ($gone == 0) {
return 0;
}
}
sub ring2 {
my $j = $_[0];
my $R = $_[1];
my $i = $_[2];
my $valence = $_[3];
my $m = $_[4];
my $n = $_[5];
my $o = $_[6];
my $p = $_[7];
my $q = $_[8];
my $r = $_[9];
my $k;
my $gone=0;
my @atoms;
my @F;
my $a;
my $return;
my $var;
my @list;
my $atom;
printf("$j $R $i $gone $array_r[$j]\n");
if ($j == 0) {
$array_r[0] = $i;
}
if ($j == $R and $array_r[$R] == $i) {
return 1;
}
for ($k = $R; $k > $j; $k--) {
$array_r[$k]=0;
}
$go_j=0;
if ($n > 0) {
if ($j == $m) {
printf("la1 $j $R $i $gone $array_r[$j]\n");
if ($Z[$array_r[$j]] != $n) {
return 0;
}
else {
$go_j = 1;
}
}
}
if ($o > 0) {
if ($j == $o) {
printf("la 2 $j $R $i $gone $array_r[$j]\n");
if ($Z[$array_r[$j]] != $p) {
return 0;
}
else {
$go_j = 1;
}
}
}
if ($q > 0) {
if ($j == $q) {
printf("la3 $j $R $i $gone $array_r[$j]\n");
if ($Z[$array_r[$j]] != $r) {
return 0;
}
else {
$go_j = 1;
}
}
}
if($array_r[$j] == 11)
{
printf("onze $go_j\n");
}
if (($Z[$array_r[$j]] == 6 and ($valence[$array_r[$j]] == $valence or $valence == 0)) or $j == 0 or $go_j == 1) {
if($array_r[$j] == 11)
{
printf("onze\n");
}
@list = split(/:/, $bond_list[$array_r[$j]]);
$k=0;
foreach $atom (@list) {
unless ($Z[$atom] == 1 or $ring[$atom][$R] == 1) {
$atoms[$k][$j] = $atom;
$k++;
}
}
$F[$j]=($k-1);
for ($k = 0; $k <= $F[$j]; $k++) {
$ok=1;
if($array_r[$j] == 11)
{
printf("onze $atoms[$k][$j]\n");
}
for ($a = 1; $a < $j; $a++) {
if ($array_r[$a] == $atoms[$k][$j]) {
$ok=0;
}
}
if ($ok == 1) {
if($array_r[$j] == 11)
{
printf("onze $atoms[$k][$j]\n");
}
$array_r[$j+1]=$atoms[$k][$j];
$gone++;
$var = &ring2(($j+1),$R,$i,$valence,$m,$n,$o,$p,$q,$r);
if ($var == 1) {
return $var;
last;
}
}
}
}
if ($gone == 0) {
return 0;
}
}
sub splitb {
my $i = $_[0];
my @list = split(/:/, $bond_list[$i]);
return @list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment