Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculations of a Circle

Status
Not open for further replies.

biobrain

MIS
Jun 21, 2007
90
GB
Dear All,

I have a data in this format shown below. The column 7,8,9 are XYZ coordinates ie (5.223 -3.687 39.735) . Now I want to write a perl script which can find a center of all these XZY points and then calculate a zsphere of 5 Angstrom radius from that center point.


ATOM 3 C MET A 1 5.223 -3.687 39.735 1.00 58.42 C
ATOM 4 O MET A 1 5.603 -4.213 38.686 1.00 59.85 O
ATOM 5 CB MET A 1 4.100 -1.444 40.158 1.00 54.79 C
ATOM 6 CG MET A 1 3.352 -1.835 41.383 1.00 55.05 C
ATOM 7 SD MET A 1 2.027 -2.986 41.020 1.00 58.28 S
ATOM 8 CE MET A 1 0.818 -2.439 42.298 1.00 58.60 C
ATOM 9 N GLU A 2 4.686 -4.400 40.723 1.00 58.64 N


Please guide me how to procced .
 
You don't know perl, probably few here know genetics. I know I have no clue what a zsphere of 5 angstrom radius is. Have you looked into Searched CPAN for bio modules? Written any perl code?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
sorry i was type to sphere , it was a typo.

I have looked at BioPerl but got no clue.

it seems to be a simple math problem. But I still not very good in PERL so that is why unable to calculate the sphere.

Well can you guide me in calculation of a center point of XYZ coordinates.

Regards

 
Well, can you show me/us what the formula/algorithm is you need to use to figure it out? My math is very rusty.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I'm a bit confused. Once you've calculated the centre point of the three coordinates, which as you have noted is a simple math problem, and you need to 'calculate a sphere of 5 Angstrom radius', what else do you need? I mean, you have the centre point and the radius, what other attributes of a sphere are relevant here?



Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
As long as you aren't concerned with mass, you don't need to go to the length of calculating a true centroid or center of gravity, which would be good news because that uses complicated calculus.

Center point
If mass is not an issue, the center point in any number of dimensions should simply be the point which falls at the average of each dimension, so you could do a standard algebraic average of x, y, and z. That won't be hard as long as you know how to read input and parse text in Perl.

Sphere
I don't know what you're doing with a sphere in Perl or how you could store it, but I'll just guess that you want to find whether a separate target point is inside that sphere. That problem can be solved by calculating your distance from the central point and comparing it to your sphere radius. Distance is not too complicated, here is an example...
Code:
$distance = toAngstroms(sqrt(
  ($centerX - $targetX) ** 2 + 
  ($centerY - $targetY) ** 2 + 
  ($centerZ - $targetZ) ** 2 + 
));

if ($distance <= $radius) {
  # Inside the sphere
}

sub toAngstroms {
  my $length = shift;

  # You write the conversion code
}

Does this help? I have a sneaking suspicion that mass is involved, in which case - good luck.
 
You'll have to read up on how to do file operations yourself, but here's the straight forward way to calculate the center of the sphere.

Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$count[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[black][b]my[/b][/black] [blue]$x_sum[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[black][b]my[/b][/black] [blue]$y_sum[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[black][b]my[/b][/black] [blue]$z_sum[/blue] = [fuchsia]0[/fuchsia][red];[/red]

[olive][b]while[/b][/olive] [red]([/red]<DATA>[red])[/red] [red]{[/red]
	[url=http://perldoc.perl.org/functions/chomp.html][black][b]chomp[/b][/black][/url][red];[/red]
	[black][b]my[/b][/black] [blue]@data[/blue] = [url=http://perldoc.perl.org/functions/split.html][black][b]split[/b][/black][/url][red];[/red]
	
	[black][b]my[/b][/black] [red]([/red][blue]$x[/blue], [blue]$y[/blue], [blue]$z[/blue][red])[/red] = [blue]@data[/blue][red][[/red][fuchsia]6[/fuchsia],[fuchsia]7[/fuchsia],[fuchsia]8[/fuchsia][red]][/red][red];[/red]
	
	[blue]$x_sum[/blue] += [blue]$x[/blue][red];[/red]
	[blue]$y_sum[/blue] += [blue]$y[/blue][red];[/red]
	[blue]$z_sum[/blue] += [blue]$z[/blue][red];[/red]
	[blue]$count[/blue]++[red];[/red]
[red]}[/red]

[black][b]my[/b][/black] [blue]$x_center[/blue] = [blue]$x_sum[/blue] / [blue]$count[/blue][red];[/red]
[black][b]my[/b][/black] [blue]$y_center[/blue] = [blue]$y_sum[/blue] / [blue]$count[/blue][red];[/red]
[black][b]my[/b][/black] [blue]$z_center[/blue] = [blue]$z_sum[/blue] / [blue]$count[/blue][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]<<"END"[/red][red];[/red]
[purple]Center Coordinates:[/purple]
[purple]   x: [blue]$x_center[/blue][/purple]
[purple]   y: [blue]$y_center[/blue][/purple]
[purple]   z: [blue]$z_center[/blue][/purple]
[red]END[/red]

[teal]__DATA__[/teal]
[teal]ATOM      3  C   MET   A   1       5.223  -3.687  39.735  1.00 58.42           C  [/teal]
[teal]ATOM      4  O   MET   A   1       5.603  -4.213  38.686  1.00 59.85           O  [/teal]
[teal]ATOM      5  CB  MET   A   1       4.100  -1.444  40.158  1.00 54.79           C  [/teal]
[teal]ATOM      6  CG  MET   A   1       3.352  -1.835  41.383  1.00 55.05           C  [/teal]
[teal]ATOM      7  SD  MET   A   1       2.027  -2.986  41.020  1.00 58.28           S  [/teal]
[teal]ATOM      8  CE  MET   A   1       0.818  -2.439  42.298  1.00 58.60           C  [/teal]
[teal]ATOM      9  N   GLU   A   2       4.686  -4.400  40.723  1.00 58.64           N  [/teal]
[tt]------------------------------------------------------------
Pragmas (perl 5.10.0) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
[/tt]

- Miller
 
Dear All,

Thanks for helping me.

I am now working on this. I will ask further if more help required. Special thanks to MillerH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top