Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
014c009e
Commit
014c009e
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
added mol-math/IntAdjacencyGraph UniqueEdgeBuilder
parent
c4f7dd86
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-math/graph/int-adjacency-graph.ts
+30
-1
30 additions, 1 deletion
src/mol-math/graph/int-adjacency-graph.ts
src/mol-model/structure/structure/unit/rings/compute.ts
+6
-16
6 additions, 16 deletions
src/mol-model/structure/structure/unit/rings/compute.ts
with
36 additions
and
17 deletions
src/mol-math/graph/int-adjacency-graph.ts
+
30
−
1
View file @
014c009e
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
*/
import
{
arrayPickIndices
}
from
'
mol-data/util
'
;
import
{
arrayPickIndices
,
cantorPairing
}
from
'
mol-data/util
'
;
import
{
LinkedIndex
}
from
'
mol-data/int
'
;
import
{
LinkedIndex
}
from
'
mol-data/int
'
;
/**
/**
...
@@ -160,6 +160,35 @@ export namespace IntAdjacencyGraph {
...
@@ -160,6 +160,35 @@ export namespace IntAdjacencyGraph {
}
}
}
}
export
class
UniqueEdgeBuilder
{
private
xs
:
number
[]
=
[];
private
ys
:
number
[]
=
[];
private
included
=
new
Set
<
number
>
();
addEdge
(
i
:
number
,
j
:
number
)
{
let
u
=
i
,
v
=
j
;
if
(
i
>
j
)
{
u
=
j
;
v
=
i
;
}
const
id
=
cantorPairing
(
u
,
v
);
if
(
this
.
included
.
has
(
id
))
return
false
;
this
.
included
.
add
(
id
);
this
.
xs
[
this
.
xs
.
length
]
=
u
;
this
.
ys
[
this
.
ys
.
length
]
=
v
;
return
true
;
}
getGraph
():
IntAdjacencyGraph
{
return
fromVertexPairs
(
this
.
vertexCount
,
this
.
xs
,
this
.
ys
);
}
// if we cant to add custom props as well
getEdgeBuiler
()
{
return
new
EdgeBuilder
(
this
.
vertexCount
,
this
.
xs
,
this
.
ys
);
}
constructor
(
public
vertexCount
:
number
)
{
}
}
export
function
fromVertexPairs
(
vertexCount
:
number
,
xs
:
number
[],
ys
:
number
[])
{
export
function
fromVertexPairs
(
vertexCount
:
number
,
xs
:
number
[],
ys
:
number
[])
{
const
graphBuilder
=
new
IntAdjacencyGraph
.
EdgeBuilder
(
vertexCount
,
xs
,
ys
);
const
graphBuilder
=
new
IntAdjacencyGraph
.
EdgeBuilder
(
vertexCount
,
xs
,
ys
);
graphBuilder
.
addAllEdges
();
graphBuilder
.
addAllEdges
();
...
...
This diff is collapsed.
Click to expand it.
src/mol-model/structure/structure/unit/rings/compute.ts
+
6
−
16
View file @
014c009e
...
@@ -4,13 +4,12 @@
...
@@ -4,13 +4,12 @@
* @author David Sehnal <david.sehnal@gmail.com>
* @author David Sehnal <david.sehnal@gmail.com>
*/
*/
import
Unit
from
'
../../unit
'
;
import
{
IntraUnitLinks
}
from
'
../links/data
'
;
import
{
Segmentation
}
from
'
mol-data/int
'
;
import
{
Segmentation
}
from
'
mol-data/int
'
;
import
{
IntAdjacencyGraph
}
from
'
mol-math/graph
'
;
import
{
LinkType
}
from
'
../../../model/types
'
;
import
{
LinkType
}
from
'
../../../model/types
'
;
import
{
StructureElement
}
from
'
../../../structure
'
;
import
{
StructureElement
}
from
'
../../../structure
'
;
import
{
sortedCantorPairing
}
from
'
mol-data/util
'
;
import
Unit
from
'
../../unit
'
;
import
{
Int
AdjacencyGraph
}
from
'
mol-math/graph
'
;
import
{
Int
raUnitLinks
}
from
'
../links/data
'
;
export
function
computeRings
(
unit
:
Unit
.
Atomic
)
{
export
function
computeRings
(
unit
:
Unit
.
Atomic
)
{
const
size
=
largestResidue
(
unit
);
const
size
=
largestResidue
(
unit
);
...
@@ -262,9 +261,7 @@ export function createIndex(rings: StructureElement.UnitIndex[][]) {
...
@@ -262,9 +261,7 @@ export function createIndex(rings: StructureElement.UnitIndex[][]) {
}
}
// create a graph where vertices are rings, edge if two rings share at least one atom
// create a graph where vertices are rings, edge if two rings share at least one atom
const
addedEdges
=
new
Set
<
number
>
();
const
graph
=
new
IntAdjacencyGraph
.
UniqueEdgeBuilder
(
rings
.
length
);
const
xs
:
RingIndex
[]
=
[],
ys
:
RingIndex
[]
=
[];
for
(
let
rI
=
0
as
RingIndex
,
_rI
=
rings
.
length
;
rI
<
_rI
;
rI
++
)
{
for
(
let
rI
=
0
as
RingIndex
,
_rI
=
rings
.
length
;
rI
<
_rI
;
rI
++
)
{
const
r
=
rings
[
rI
];
const
r
=
rings
[
rI
];
...
@@ -278,19 +275,12 @@ export function createIndex(rings: StructureElement.UnitIndex[][]) {
...
@@ -278,19 +275,12 @@ export function createIndex(rings: StructureElement.UnitIndex[][]) {
for
(
let
j
=
0
,
_j
=
containedRings
.
length
;
j
<
_j
;
j
++
)
{
for
(
let
j
=
0
,
_j
=
containedRings
.
length
;
j
<
_j
;
j
++
)
{
const
rJ
=
containedRings
[
j
];
const
rJ
=
containedRings
[
j
];
if
(
rI
>=
rJ
)
continue
;
if
(
rI
>=
rJ
)
continue
;
graph
.
addEdge
(
rI
,
rJ
);
const
edgeIndex
=
sortedCantorPairing
(
rI
,
rJ
);
if
(
addedEdges
.
has
(
edgeIndex
))
continue
;
addedEdges
.
add
(
edgeIndex
);
xs
[
xs
.
length
]
=
rI
;
ys
[
ys
.
length
]
=
rJ
;
}
}
}
}
}
}
const
graph
=
IntAdjacencyGraph
.
fromVertexPairs
(
rings
.
length
,
xs
,
ys
);
const
components
=
IntAdjacencyGraph
.
connectedComponents
(
graph
.
getGraph
());
const
components
=
IntAdjacencyGraph
.
connectedComponents
(
graph
);
const
ringComponentIndex
=
components
.
componentIndex
as
any
as
RingComponentIndex
[];
const
ringComponentIndex
=
components
.
componentIndex
as
any
as
RingComponentIndex
[];
const
ringComponents
:
RingIndex
[][]
=
[];
const
ringComponents
:
RingIndex
[][]
=
[];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment