Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 2023-R5.1 into Master #696

Merged
merged 14 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions api/scripts/mtz2map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,35 @@ export CLIBD=$CCP4_MASTER/lib/data
export CCP4_SCR=/tmp
export root=$CCP4_MASTER/bin

if [ -f $1 ]; then
mtz=$1
else
if [ -f $1.gz ]; then
mtz=/tmp/$2_$3.mtz
gunzip -c $1.gz > $mtz
else
echo "No mtz file found"
exit
fi
fi

if [ $3 == 'dimple' -o $3 == 'mrbump' ]; then

if [ -f $4 ]; then
pdb=$4
else
if [ -f $4.gz ]; then
pdb=/tmp/$2_$3.pdb
gunzip -c $4.gz > $pdb
else
echo "No pdb file found"
exit
fi
fi

if [ $3 == 'dimple' ]; then
# fofc2="F1=F SIG1=SIGF PHI=PH2FOFCWT W=FOM"
# fofc="F1=F SIG1=SIGF PHI=PHFOFCWT W=FOM"
# fofc2="F1=F SIG1=SIGF PHI=PHWT W=FOM"
# fofc="F1=F SIG1=SIGF PHI=PHDELWT W=FOM"

if $root/mtzinfo $1 | grep -q PH2FOFCWT; then
if $root/mtzinfo $mtz | grep -q PH2FOFCWT; then
fofc2="F1=2FOFCWT SIG1=SIGF PHI=PH2FOFCWT"
fofc="F1=F SIG1=SIGF PHI=PHFOFCWT W=FOM"
else
Expand All @@ -37,7 +57,7 @@ fi

# F SIGF FC PHIC FC_ALL PHIC_ALL FWT PHWT DELFWT PHDELWT FOM FC_ALL_LS PHIC_ALL_LS

$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3_2fofc.map.tmp" << eof
$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3_2fofc.map.tmp" << eof
title $2 2fofc
xyzlim asu
scale F1 1.0
Expand All @@ -46,11 +66,11 @@ $fofc2
end
eof

$root/mapmask MAPIN "/tmp/$2_$3_2fofc.map.tmp" MAPOUT "/tmp/$2_$3_2fofc.map" XYZIN "$4" << eof
$root/mapmask MAPIN "/tmp/$2_$3_2fofc.map.tmp" MAPOUT "/tmp/$2_$3_2fofc.map" XYZIN "$pdb" << eof
BORDER 5
eof

$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3_fofc.map.tmp" << eof
$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3_fofc.map.tmp" << eof
title $2 fofc
xyzlim asu
scale F1 1.0
Expand All @@ -60,16 +80,17 @@ end
eof


$root/mapmask MAPIN "/tmp/$2_$3_fofc.map.tmp" MAPOUT "/tmp/$2_$3_fofc.map" XYZIN "$4" << eof
$root/mapmask MAPIN "/tmp/$2_$3_fofc.map.tmp" MAPOUT "/tmp/$2_$3_fofc.map" XYZIN "$pdb" << eof
BORDER 5
eof

gzip "/tmp/$2_$3_2fofc.map"
gzip "/tmp/$2_$3_fofc.map"

rm -f /tmp/$2_$3.pdb

else
$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3.map" << eof
$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3.map" << eof
title $2 fofc
xyzlim asu
scale F1 1.0
Expand All @@ -78,10 +99,8 @@ F1=F SIG1=SIGF PHI=PHI W=FOM
end
eof

#$mm MAPIN "/tmp/$2_ep.map.tmp" MAPOUT "/tmp/$2_ep.map" XYZIN "$4" << eof
#BORDER 5
#eof

gzip "/tmp/$2_$3.map"

fi

rm -f /tmp/$2_$3.mtz
69 changes: 32 additions & 37 deletions api/src/Authentication/Type/OIDC.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,41 @@

class OIDC extends AuthenticationParent implements AuthenticationInterface
{
private $providerConfig = array();
//** Cache for providerConfig */
private $providerConfigCache = null;

function __construct() {
private function getProviderConfig() {
global $sso_url, $oidc_client_id, $oidc_client_secret;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $sso_url . '/.well-known/openid-configuration');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errno = curl_errno($ch);

if ($errno || $http_code != 200) {
error_log("Failed to connect to OIDC discovery endpoint. HTTP code: " . $http_code . ". CURL err. no.: " . $errno);
return;
}

curl_close($ch);
$newProviderConfig = json_decode($response);

if(!$newProviderConfig
|| !isset($newProviderConfig->userinfo_endpoint)
|| !isset($newProviderConfig->authorization_endpoint)
|| !isset($newProviderConfig->token_endpoint)) {
error_log("OIDC Authentication provider replied with invalid JSON discovery body");
return;
if (is_null($this->providerConfigCache)) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $sso_url . '/.well-known/openid-configuration');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$newProviderConfig = json_decode($response);

if(!$newProviderConfig
|| !isset($newProviderConfig->userinfo_endpoint)
|| !isset($newProviderConfig->authorization_endpoint)
|| !isset($newProviderConfig->token_endpoint)) {
error_log("OIDC Authentication provider replied with invalid JSON body");
return null;
}
$newProviderConfig->b64ClientCreds = base64_encode(
$oidc_client_id . ":" . $oidc_client_secret
);

$this->providerConfigCache = $newProviderConfig;
}
$newProviderConfig->b64ClientCreds = base64_encode(
$oidc_client_id . ":" . $oidc_client_secret
);

$this->providerConfig = $newProviderConfig;
return $this->providerConfigCache;
}

private function getUser($token)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->providerConfig->userinfo_endpoint);
curl_setopt($ch, CURLOPT_URL, $this->getProviderConfig()->userinfo_endpoint);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Expand Down Expand Up @@ -82,7 +78,7 @@ function authorise()
global $oidc_client_id;
$redirect_url = Utils::filterParamFromUrl($_SERVER["HTTP_REFERER"], "code");

return ( $this->providerConfig->authorization_endpoint .
return ( $this->getProviderConfig()->authorization_endpoint .
'?response_type=code&client_id=' . $oidc_client_id .
'&redirect_uri=' . $redirect_url
);
Expand All @@ -95,14 +91,14 @@ function authenticateByCode($code)
$redirect_url = Utils::filterParamFromUrl($_SERVER["HTTP_REFERER"], "code");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->providerConfig->token_endpoint .
curl_setopt($ch, CURLOPT_URL, $this->getProviderConfig()->token_endpoint .
'?grant_type=authorization_code&redirect_uri=' .
$redirect_url .
"&code=" . $code
);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->providerConfig->b64ClientCreds));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->getProviderConfig()->b64ClientCreds));
$response = curl_exec($ch);
curl_close($ch);

Expand All @@ -113,14 +109,14 @@ function authenticateByCode($code)
}

$token = $response_json->access_token;

if(!$token) {
error_log("Invalid authentication attempt, provider returned no access token");
return false;
}

$cookieOpts = array (
'expires' => time() + 60*60*24,
'expires' => time() + $response_json->expires_in,
'path' => '/',
'secure' => true,
'httponly' => true,
Expand All @@ -131,4 +127,3 @@ function authenticateByCode($code)
return $this->getUser($token);
}
}

8 changes: 6 additions & 2 deletions api/src/Downstream/BigEPPhasing.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ function results() {
}

$image = $this->_get_image();
$dat['IMAGE'] = file_exists($image);
$dat['IMAGE'] = file_exists($image) || file_exists($image.'.gz');

$model = $this->_get_attachments('big_ep_model_ispyb.json');
$dat['HASMODEL'] = $model && file_exists($model['FILE']);
$dat['HASMODEL'] = $model && (file_exists($model['FILE']) || file_exists($model['FILE'].'.gz'));
if ($model) {
if (file_exists($model['FILE'])) {
$json_str = file_get_contents($model['FILE']);
} elseif (file_exists($model['FILE'].'.gz')) {
$json_str = gzdecode(file_get_contents($model['FILE'].'.gz'));
}
if (isset($json_str)) {
$json_data = json_decode($json_str, true);
foreach (
array(
Expand Down
142 changes: 77 additions & 65 deletions api/src/Downstream/Type/FastEp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,83 +16,95 @@ function results() {
$pdb = $this->_get_attachments("sad_fa.pdb");
if ($pdb) {
if (file_exists($pdb["FILE"])) {
$pdb = file_get_contents($pdb["FILE"]);
foreach (explode("\n", $pdb) as $l) {
if (strpos($l, 'HETATM') !== false) {
$parts = preg_split('/\s+/', $l);
array_push($ats, array(
$parts[1],
$parts[5],
$parts[6],
$parts[7],
$parts[8],
));
}
}
$pdb_cont = file_get_contents($pdb["FILE"]);
} elseif (file_exists($pdb['FILE'].'.gz')) {
$pdb_cont = gzdecode(file_get_contents($pdb['FILE'].'.gz'));
}
}

$dat['ATOMS'] = array_slice($ats, 0, 5);
if (isset($pdb_cont)) {
foreach (explode("\n", $pdb_cont) as $l) {
if (strpos($l, 'HETATM') !== false) {
$parts = preg_split('/\s+/', $l);
array_push($ats, array(
$parts[1],
$parts[5],
$parts[6],
$parts[7],
$parts[8],
));
}
}

$dat['ATOMS'] = array_slice($ats, 0, 5);

}

$lst = $this->_get_attachments("sad.lst");
if ($lst) {
if (file_exists($lst['FILE'])) {
$p1 = array();
$p2 = array();

$lst = file_get_contents($lst['FILE']);
$graph_vals = 0;
$gvals = array();
foreach (explode("\n", $lst) as $l) {
if (
strpos(
$l,
'Estimated mean FOM and mapCC as a function of resolution'
) !== false
) {
$graph_vals = 1;
}

if ($graph_vals && $graph_vals < 5) {
array_push($gvals, $l);
$graph_vals++;
}

if (
preg_match(
'/ Estimated mean FOM = (\d+.\d+)\s+Pseudo-free CC = (\d+.\d+)/',
$l,
$mat
)
) {
$dat['FOM'] = floatval($mat[1]);
$dat['CC'] = floatval($mat[2]);
}
$lst_cont = file_get_contents($lst['FILE']);
} elseif (file_exists($lst['FILE'].'.gz')) {
$lst_cont = gzdecode(file_get_contents($lst['FILE'].'.gz'));
}
}

if (isset($lst_cont)) {
$p1 = array();
$p2 = array();

$graph_vals = 0;
$gvals = array();
foreach (explode("\n", $lst_cont) as $l) {
if (
strpos(
$l,
'Estimated mean FOM and mapCC as a function of resolution'
) !== false
) {
$graph_vals = 1;
}

if (sizeof($gvals) > 0) {
$x = array_map(
'floatval',
array_slice(explode(' - ', $gvals[1]), 1)
);
$y = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[2]), 2)
);
$y2 = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[3]), 2)
);

foreach ($x as $i => $v) {
array_push($p1, array(1.0 / pow($v, 2), $y[$i]));
array_push($p2, array(1.0 / pow($v, 2), $y2[$i]));
}
if ($graph_vals && $graph_vals < 5) {
array_push($gvals, $l);
$graph_vals++;
}

$dat['PLOTS']['FOM'] = $p1;
$dat['PLOTS']['CC'] = $p2;
if (
preg_match(
'/ Estimated mean FOM = (\d+.\d+)\s+Pseudo-free CC = (\d+.\d+)/',
$l,
$mat
)
) {
$dat['FOM'] = floatval($mat[1]);
$dat['CC'] = floatval($mat[2]);
}
}

if (sizeof($gvals) > 0) {
$x = array_map(
'floatval',
array_slice(explode(' - ', $gvals[1]), 1)
);
$y = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[2]), 2)
);
$y2 = array_map(
'floatval',
array_slice(preg_split('/\s+/', $gvals[3]), 2)
);

foreach ($x as $i => $v) {
array_push($p1, array(1.0 / pow($v, 2), $y[$i]));
array_push($p2, array(1.0 / pow($v, 2), $y2[$i]));
}
}

$dat['PLOTS']['FOM'] = $p1;
$dat['PLOTS']['CC'] = $p2;

}

$results = new DownstreamResult($this);
Expand Down
Loading
Loading